由于上下班要带电脑,所以难免要切换网关,IP,DNS等,花了2个小时的成果,写成了函数供调用
本人QQ:312782705 希望大家共同学习,分享- On Error Resume Next
- Set moWindow=WScript.CreateObject("InternetExplorer.Application", "IE_")
- moWindow.Navigate2 "about:blank"
- With moWindow.Document.ParentWindow
- .Document.Write "<input type='button' value='一键修改网关192.168.0.1' name='Button'/></br>"
- .Document.Write "<input type='button' value='一键修改网关192.168.1.1' name='Button2'/></br>"
- .Document.Write "<input type='text' size='30' name='ip'/><input type='text' size='30' name='xip'/></br>"
- .Document.Write "<input type='text' size='30' name='mac'/><input type='text' size='30' name='xmac'/></br>"
- .Document.Write "<input type='text' size='30' name='dhcp'/><input type='text' size='30' name='xdhcp'/></br>"
- .Document.Write "<input type='text' size='30' name='IPGateway'/><input type='text' size='30' name='xIPGateway'/></br>"
- .Document.Write "<input type='text' size='30' name='IPSubnet'/><input type='text' size='30' name='xIPSubnet'/></br>"
- .Document.Write "<input type='text' size='30' name='DNS1'/><input type='text' size='30' name='xDNS1'/></br>"
- .Document.Write "<input type='text' size='30' name='DNS2'/><input type='text' size='30' name='xDNS2'/></br>"
- .Document.Write "<input type='button' value='自定义修改IP网关DNS等' name='IPset'/></br><body background='//1.jpg'>
- <body bgcolor='#0000'></br></br></br>"
- .Document.Write "<input type='button' value=' 一键获取本机设置 ' name='getip'/></br>"
- .MoveTo .Screen.AvailWidth/2-140,.Screen.AvailHeight/2-225
- .ResizeTo 280,650
- .Document.Title="沈寂 高级IP修改器 QQ:312782705"
- End With
- moWindow.Document.Close
- With moWindow
- .FullScreen=0
- .MenuBar=0
- .AddressBar=0
- .ToolBar=0
- .StatusBar=0
- .Resizable=0
- .Visible=1
- Set Form=.Document.All
- Set .Document.All.Button.onClick=GetRef("Button_onClick")
- Set .Document.All.Button2.onClick=GetRef("Button2_onClick")
- Set .Document.All.IPset.onClick=GetRef("IPset_onClick")
- Set .Document.All.getip.onClick=GetRef("getip_onClick")
- End With
- mbFinished=False
- Do Until mbFinished
- WScript.Sleep 50
- Loop
- '____________________________________________________________________________退出代码
- Sub IE_onQuit
- mbFinished=True
- End Sub
- '____________________________________________________________________________自定义1
- Sub Button_onClick
- xiugaiip "192.168.0.74","192.168.0.1","255.255.255.0","202.96.199.132","202.96.209.5"
- End Sub
- '____________________________________________________________________________自定义2
- Sub Button2_onClick
- xiugaiip "192.168.1.74","192.168.1.1","255.255.255.0","202.96.199.132","202.96.209.5"
- End Sub
- ''____________________________________________________________________________自定义修改IP
- Sub IPset_onClick
- if (moWindow.Document.All.IPset.value="填写好了,确定修改") then
- msgbox "123"
- xiugaiip moWindow.Document.All.xip.value,moWindow.Document.All.xIPGateway.value,moWindow.Document.All.xIPSubnet.value,moWindow.Document.All.xDNS1.value,moWindow.Document.All.xDNS1.value
- else
- moWindow.Document.ParentWindow.ResizeTo 580,450
- getip_onClick
- msgbox "左边为本机原始设置,请在右边填写你修改后的设置",,"提示"
- moWindow.Document.All.IPset.value="填写好了,确定修改"
- end if
- End Sub
- '____________________________________________________________________________获取本机设置
- Sub getip_onClick
- Dim objWMIService,colItems,objItem,objAddress
- Set bjWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
- Set colItems =bjWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
- For Each objItem in colItems
- For Each objAddress in objItem.IPAddress
- If objAddress <> "" then
- IP = objAddress 'IP地址
- mac =objItem.MACAddress 'MAC地址
- DHCPEnabled=objItem.DHCPEnabled '是否启用DHCP
- DefaultIPGateway=objItem.DefaultIPGateway(0) '网关
- IPSubnet=objItem.IPSubnet(0) '子网掩码
- DNSServerSearchOrder1=objItem.DNSServerSearchOrder(0) 'DNS设置1
- DNSServerSearchOrder2=objItem.DNSServerSearchOrder(1) 'DNS设置2
- Exit For
- End If
- Next
- Exit For
- Next
- moWindow.Document.All.ip.value="IP地址是:" & ip
- moWindow.Document.All.xip.value=ip
- moWindow.Document.All.mac.value="MAC地址是::" & mac
- moWindow.Document.All.xmac.value="不能修改"
- moWindow.Document.All.dhcp.value="是否启用DHCP:" & DHCPEnabled
- moWindow.Document.All.xdhcp.value="不能修改"
- moWindow.Document.All.IPGateway.value="网关是:" & DefaultIPGateway
- moWindow.Document.All.xIPGateway.value=DefaultIPGateway
- moWindow.Document.All.IPSubnet.value="子网掩码是:" & IPSubnet
- moWindow.Document.All.xIPSubnet.value=IPSubnet
- moWindow.Document.All.DNS1.value="DNS1:" & DNSServerSearchOrder1
- moWindow.Document.All.xDNS1.value=DNSServerSearchOrder1
- moWindow.Document.All.DNS2.value="DNS2:" & DNSServerSearchOrder2
- moWindow.Document.All.xDNS2.value=DNSServerSearchOrder2
- End Sub
- '____________________________________________________________________________自定义修改函数
- Function xiugaiip(ip,IPGateway,IPSubnet,DNS1,DNS2)
- STR_GATEWAY = IPGateway
- STR_NEWDNS1 = DNS1
- STR_NEWDNS2 = DNS2
- STR_IP = ip
- STR_zwym=IPSubnet
- Set fs=CreateObject("Scripting.FileSystemObject")
- strWinMgmt="winmgmts:{impersonationLevel=impersonate}"
- Set objNICs = GetObject( strWinMgmt ).InstancesOf("Win32_NetworkAdapterConfiguration")
- For Each objNIC In objNICs
- If objNIC.IPEnabled Then
- objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
- objNIC.SetGateways Array(STR_GATEWAY)
- End If
- Next
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
- Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True")
- strIPAddress = Array(STR_IP)
- strSubnetMask = Array(IPSubnet)
- For Each objNetAdapter in colNetAdapters
- errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
- Next
- msgbox "已经设置为" & vbcrlf & "网关:" & IPGateway & vbcrlf & "ip地址:" & ip & vbcrlf & "子网掩码:" & IPSubnet & vbcrlf & "DNS1:" & DNS1 & vbcrlf & "DNS2:" &DNS2,,"提示"
- end Function
复制代码
[ 本帖最后由 ipqfhvk 于 2010-12-12 18:03 编辑 ] |