windows7/windows2008修改远程桌面连接并修改防火墙配置脚本

本文涉及的产品
云防火墙,500元 1000GB
简介:

一、说明

      为了安全我们经常对windows的管理都会修改默认的远程连接端口(tcp 3389)为其他的端口,要连接管理的windows机器一多,修改起来就比较烦琐,再加上修改防火墙,就更是麻烦,而且修改出错可能把自己关在外面,无法登录系统 ,所以此时你需要一个脚本工具一键修改端口,修改防火墙,备份修改前的注册表。


二、脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@ echo  off
@ echo  [远程桌面端口修改]
  CLS
  MODE con: COLS=68 LINES=20
  :: MODE语句为设定窗体的宽和高
 
SetLocal EnableDelayedExpansion
  set /p  d= "输入新的远程桌面端口:"
  set  port=%d%
  echo  将修改远程桌面端口为[%d%].
  echo  如果启用了的[系统防火墙] 或 [IPSec策略] 或 [TCP /IP 筛选]以及
  echo  其他防护软件允许该[%d%]端口通过.否则有可能被关在系统外面,导致系统无法远程连接!!
  echo  按任意键继续操作...
  pause>nul
  set  Str=0123456789ABCDEF
  :loop
  set /a  y=%d%%%16
  set /a  d=%d%% /16
  set  y=!Str:~%y%,1!
  set  e=%y%%e%
  if  %d% geq 1 goto loop
  echo  ------------------------------------------------------
  echo  正在创建注册表文件.
  ping  -n 2 127.0.1>nul
  echo  Windows Registry Editor Version 5.00> c:\Remote.reg
  echo  [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp]>> c:\Remote.reg
  echo  "PortNumber" =dword:0000%e%>> c:\Remote.reg
  echo  [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp]>> c:\Remote.reg
  echo  "PortNumber" =dword:0000%e%>> c:\Remote.reg
  echo  正在导入注册表文件以更改系统默认设置.
  ping  -n 2 127.0.1>nul
  regedit  /s  c:\Remote.reg
  del c:\Remote.reg &&  echo  临时文件已经删除.
  ping  -n 2 127.0.1>nul
  echo  ------------------------------------------------------
 
  echo  端口已经修改完毕(重启生效!),修改防火墙策略.
  netsh advfirewall firewall delete rule name= "mstsc_port%port%"
  netsh advfirewall firewall add rule name= "mstsc_port%port%"  protocol=TCP  dir = in  localport= "%port%"  action=allow remoteip=
  echo  防火墙打开远程端口[%port%] 成功!
  echo  按任意键退出...
  pause>nul

  三、补充--通过python对防火墙头添加规则

通过python实时添加ip及服务端口进行黑名单添加

1
2
3
4
5
6
import  os
import  time
#添加
os.system( "netsh advfirewall firewall add rule name=%s dir=in action=block protocol=TCP remoteip=%s localport=%s"  % ( "deny_3389" , "172.16.3.140" , 3389 ))
#删除
os.system( "netsh advfirewall firewall delete rule name=%s "  %  "deny_3389" )









本文转自 dyc2005 51CTO博客,原文链接:http://blog.51cto.com/dyc2005/1942075,如需转载请自行联系原作者
目录
相关文章
|
21天前
|
安全 Unix 虚拟化
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 2 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 2 月更新)
44 11
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 2 月更新)
|
4月前
|
数据库连接 数据库 C#
Windows下C# 通过ADO.NET方式连接南大通用GBase 8s数据库(上)
Windows下C# 通过ADO.NET方式连接南大通用GBase 8s数据库(上)
|
4月前
|
数据库连接 数据库 C#
Windows下C# 通过ADO.NET方式连接南大通用GBase 8s数据库(下)
本文接续前文,深入讲解了在Windows环境下使用C#和ADO.NET操作南大通用GBase 8s数据库的方法。通过Visual Studio 2022创建项目,添加GBase 8s的DLL引用,并提供了详细的C#代码示例,涵盖数据库连接、表的创建与修改、数据的增删查改等操作,旨在帮助开发者提高数据库管理效率。
|
5月前
|
监控 网络协议 Shell
ip和ip网段攻击拦截系统-绿叶结界防火墙系统shell脚本
这是一个名为“小绿叶技术博客扫段攻击拦截系统”的Bash脚本,用于监控和拦截TCP攻击。通过抓取网络数据包监控可疑IP,并利用iptables和firewalld防火墙规则对这些IP进行拦截。同时,该系统能够查询数据库中的白名单,确保合法IP不受影响。此外,它还具备日志记录功能,以便于后续分析和审计。
110 6
|
5月前
|
监控 关系型数据库 MySQL
PowerShell 脚本编写 :自动化Windows 开发工作流程
PowerShell 脚本编写 :自动化Windows 开发工作流程
234 0
|
5月前
|
Apache 数据中心 Windows
将网站迁移到阿里云Windows系统云服务器,访问该站点提示连接被拒绝,如何处理?
将网站迁移到阿里云Windows系统云服务器,访问该站点提示连接被拒绝,如何处理?
|
5月前
|
弹性计算 安全 Windows
通过远程桌面连接Windows服务器提示“由于协议错误,会话将被中断,请重新连接到远程计算机”错误怎么办?
通过远程桌面连接Windows服务器提示“由于协议错误,会话将被中断,请重新连接到远程计算机”错误怎么办?
|
5月前
|
关系型数据库 MySQL Linux
Navicat 连接 Windows、Linux系统下的MySQL 各种错误,修改密码。
使用Navicat连接Windows和Linux系统下的MySQL时可能遇到的四种错误及其解决方法,包括错误代码2003、1045和2013,以及如何修改MySQL密码。
646 0
|
6月前
|
网络协议 API Windows
MASM32编程调用 API函数RtlIpv6AddressToString,windows 10 容易,Windows 7 折腾
MASM32编程调用 API函数RtlIpv6AddressToString,windows 10 容易,Windows 7 折腾
|
6月前
|
Python Windows
python之windows脚本启动bat
python之windows脚本启动bat