au3实现ip地址改变达到控制能否上网目的

单位最近要上新设备,说是每个人一个ip以后上级要绑定ip和个人,会查看个人上网行为。

头疼的是,单位的ip很乱,而且涉及很多人共用一台电脑的问题,怎么能让他们在不用学会如何改ip的情况下就能在上网时把ip改成自己的,离开电脑时把ip改成不能用的呢?

最终我想了一个笨办法,就是用ip切换的功能实现。

当要上网时,运行这个文件,点击上网,把ip设置成个人的ip,然后要离开电脑时,再把ip设置成一个根本没办法用的一串1的ip地址就行了。

呵呵,很笨吧?不过好用。代码如下:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$IP = GUICreate("上网保证器", 341, 79, 192, 132)
$Button1 = GUICtrlCreateButton("上网", 24, 16, 129, 49)
$Button2 = GUICtrlCreateButton("离开", 183, 16, 129, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  
  Case $Button1
   shangwang()
   Exit
  Case $Button2
   likai()
   Exit

 EndSwitch
WEnd


Func likai()
$IP = "01.01.01.01"
$zwym = "01.01.01"
$router = "01.01.01.01"
$dns = "01.01.0101"
;修改IP,dns,路由为不能用的号段
RunWait('netsh interface ip set address name = "本地连接"  source = static addr = ' & $IP & ' mask = ' & $zwym & ' gateway = ' & $router & ' gwmetric = 0', "c:\windows\system32", @SW_HIDE)
RunWait('netsh interface ip set dns name = "本地连接"  source = static addr = ' & $dns & ' register = PRIMARY', "c:\windows\system32", @SW_HIDE)
EndFunc


Func shangwang()
$IP = "个人ip"
$zwym = "255.255.255.0"
$router = "单位路由ip"
$dns = "单位的dns"
;修改IP,dns,路由为可用号码,如个人ip写192.168.1.2,单位路由ip写192.168.1.1,单位dns写当地网通的dns
RunWait('netsh interface ip set address name = "本地连接"  source = static addr = ' & $IP & ' mask = ' & $zwym & ' gateway = ' & $router & ' gwmetric = 0', "c:\windows\system32", @SW_HIDE)
RunWait('netsh interface ip set dns name = "本地连接"  source = static addr = ' & $dns & ' register = PRIMARY', "c:\windows\system32", @SW_HIDE)
EndFunc

到这里写完了,但是,有一个小问题,就是这玩意自动关闭很慢,不知道为什么,反正代码是抄的,问我我也看不懂,总之,大约十五六个数之内肯定可以退出的。就是搞不懂。回头再研究吧。呵呵。写完拉倒。

命令行改DNS存在一定的BUG,有时候不一定修改成功,论坛用户需要,我特别写了一个。 SETDNS.AU3 #Region ;**** 参数创建于 ACNWrapper_GUI **** #AutoIt3Wrapper_Icon=ip.ico #AutoIt3Wrapper_Outfile=SETDNS.exe #AutoIt3Wrapper_UseAnsi=y #AutoIt3Wrapper_Res_Comment=DNS修改工具 #AutoIt3Wrapper_Res_Description=DNS修改工具 #AutoIt3Wrapper_Res_Fileversion=1.0.0.2 #AutoIt3Wrapper_Res_LegalCopyright=TVZML作品 #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** 参数创建于 ACNWrapper_GUI **** Break(0) $g_Tray = "DNS修改工具" If WinExists($g_Tray) = 1 Then Exit AutoItWinSetTitle("DNS修改工具") $dir = (@ScriptDir & "\DNS.ini") $SectionNames = "配置信息" _setip() Exit Func _setip() ;导入IP配置 If Not FileExists($dir) Then MsgBox(16, "错误", "没有找到配置文件" & @CRLF & $dir, 3) Exit EndIf $colItems = "" $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2") Dim $SetDns[2] $SetDns[0] = IniRead($dir, $SectionNames, "首选DNS", "") $SetDns[1] = IniRead($dir, $SectionNames, "备用DNS", "") TrayTip("", "正在设置DNS,请稍等...", 1) $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20) $colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem") If IsObj($colItems) Then For $objNetAdapter In $colItems $objNetAdapter.SetDNSServerSearchOrder($SetDns) Next EndIf Exit EndFunc ;==>_setip 配置文件样式 DNS.ini [配置信息] 首选DNS=220.189.127.106 备用DNS=220.189.127.108
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值