流浪628
发表于 2011-12-1 11:37:23
回复 15# 兔子先生
这个本来有的,我把哪个给取消了,因为我们只要个这固定IP。其它的都不能给上面添的。只要改一下标签。就可以改回去的。
y1751
发表于 2011-12-1 12:09:39
回复 11# 流浪628
我也修改了Dns,是我自己用的。呵呵
流浪628
发表于 2011-12-1 13:18:33
回复 17# y1751
哦,呵呵,这个有一部分是别人给我提出的思路,他说我这取之于民要用之于民,所以才让我把这个发出来,你要是早发出来,我也就不会花两天时间,去调试哪个错误了。
lpxx
发表于 2011-12-1 15:07:37
看在我们机器配置相近的情况下支持一下。
6FINGERS
发表于 2011-12-1 16:51:24
回复 10# 流浪628
这个几多年前大大们发烂了的,你现在说这个小功能它值?
流浪628
发表于 2011-12-1 18:25:25
回复 20# 6FINGERS
几年前是发烂了,可是到现在官方里面的DNS改值也只能改一个。
haijie1223
发表于 2011-12-2 20:12:03
楼主的代码还是有些问题的,我来帮你开放,让更多的人查阅。
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <Date.au3>
;#Include <ACN_NET.au3>
#Include <WinAPI.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#Region ### START Koda GUI section ### Form=E:\作品\Form2-1.kxf
Global Const $NetworkAdapterInfo = _NetworkAdapterInfo();获得网卡信息.
Global Const $ScriptDir=@ScriptDir & '\'& "ip.ini"
Global Const $OSVersion= @OSVersion
MsgBox("1","sadf",$OSVersion)
;Global Const $ScriptDir1=@ScriptDir & '\'& "ip.ini")
Global $hIcons
$Form2_1 = GUICreate("IP地址修改器", 709, 455, 271, 152)
$Group1 = GUICtrlCreateGroup("自动获取", 32, 8, 609, 441)
$Label1 = GUICtrlCreateLabel("网卡选择", 78, 32, 52, 17)
$Label2 = GUICtrlCreateLabel("计算机名", 78, 88, 52, 17)
$Input1 = GUICtrlCreateLabel("Input1", 152, 88, 329, 21)
$Label3 = GUICtrlCreateLabel("IP地址", 78, 144, 38, 17)
$Combo1 = GUICtrlCreateCombo("选择的网卡", 160, 24, 329, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL));选择的网卡
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKHEIGHT)
$Input2 = GUICtrlCreateLabel("IP地址", 152, 144, 169, 21)
$Label4 = GUICtrlCreateLabel("网关地址", 78, 192, 52, 17)
$Input3 = GUICtrlCreateLabel("网关", 152, 192, 169, 21)
$Label5 = GUICtrlCreateLabel("首选DNS", 78, 248, 51, 17)
$Input4 = GUICtrlCreateLabel("DNS", 152, 248, 169, 21)
$Label6 = GUICtrlCreateLabel("子网掩码", 336, 144, 52, 17)
$Input5 = GUICtrlCreateLabel("子网掩码", 392, 144, 169, 21)
$Label7 = GUICtrlCreateLabel("备用DNS", 336, 248, 51, 17)
$Input6 = GUICtrlCreateLabel("DNS", 392, 248, 169, 21)
$Button1 =GUICtrlCreateButton("执行", 208, 368, 113, 57)
$Button2 = GUICtrlCreateButton("退出", 368, 368, 113, 57)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;在GUI上创建一个分组(Group)控件
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$hStatus = _GUICtrlStatusBar_Create ($Form2_1);If using GUICtrlCreateMenu then use _GUICtrlStatusBar_Create after GUICtrlCreateMenu
Global $aParts =
_GUICtrlStatusBar_SetParts ($hStatus, $aParts)
_GUICtrlStatusBar_SetText ($hStatus, " IP 地址修改器内部专用版本",0)
_GUICtrlStatusBar_SetText ($hStatus, " 酒店事业部", 1)
_GUICtrlStatusBar_SetIcon ($hStatus, 0, -19, "shell32.dll")
_GUICtrlStatusBar_SetIcon ($hStatus, 1, 221, "shell32.dll")
$hIcons = _WinAPI_LoadShell32Icon (-19)
$hIcons = _WinAPI_LoadShell32Icon (221)
_GUICtrlStatusBar_SetIcon ($hStatus, 0, $hIcons)
_GUICtrlStatusBar_SetIcon ($hStatus, 1, $hIcons)
;_ArrayDisplay($NetworkAdapterInfo)
;保存IP地址和往输入框里填写固定IP。
For $i=1 To $NetworkAdapterInfo
GUICtrlSetData($Combo1,$NetworkAdapterInfo,$NetworkAdapterInfo)
;获取IP、子网掩码、网关并保存在IP.INI文件里,并将要改的IP地址显示在输入框里。
If $NetworkAdapterInfo[$i] = 0 Then
GUICtrlSetData($Combo1,"没有找到可用的网卡信息^_^")
Else
If $NetworkAdapterInfo = True Then
IniWrite ( $ScriptDir, "DHCP", "dhcp值", "True")
GUICtrlSetData($Input1,@ComputerName)
GUICtrlSetData($Input2,"192.168.1.82")
GUICtrlSetData($Input3,"192.168.1.1")
GUICtrlSetData($Input4,"202.106.0.20")
GUICtrlSetData($Input5,"255.255.255.0")
GUICtrlSetData($Input6,"210.82.5.1")
MsgBox("1","wert","DHCP状态已保存")
EndIf
If $NetworkAdapterInfo = False then
IniWrite ( $ScriptDir, "DHCP", "dhcp值", "False")
IniWrite ( $ScriptDir, $NetworkAdapterInfo, "ip地址", $NetworkAdapterInfo)
IniWrite ( $ScriptDir, $NetworkAdapterInfo, "子网掩码",$NetworkAdapterInfo)
IniWrite ( $ScriptDir, $NetworkAdapterInfo, "网关地址",$NetworkAdapterInfo)
IniWrite ( $ScriptDir, $NetworkAdapterInfo, "首选DNS",$NetworkAdapterInfo)
IniWrite ( $ScriptDir, $NetworkAdapterInfo, "备用DNS",$NetworkAdapterInfo)
GUICtrlSetData($Input1,@ComputerName)
GUICtrlSetData($Input2,"192.168.1.82")
GUICtrlSetData($Input3,"192.168.1.1")
GUICtrlSetData($Input4,"202.106.0.20")
GUICtrlSetData($Input5,"255.255.255.0")
GUICtrlSetData($Input6,"210.82.5.1")
MsgBox("1","wert","ip地址:"&$NetworkAdapterInfo&@CRLF&"子网掩码:"&$NetworkAdapterInfo&@CRLF&"网关地址:"&$NetworkAdapterInfo&@CRLF&"首选DNS:"&$NetworkAdapterInfo&@CRLF&"备用DNS:"&$NetworkAdapterInfo&@CRLF&"都已保存")
EndIf
EndIf
Next
;捕获IP和修改IP,和恢复原来的IP地址。
While 1
$nMsg = GUIGetMsg() ;捕获窗口消息
Switch $nMsg
Case $GUI_EVENT_CLOSE;对话框(窗口)正被关闭(相关按钮被点击或系统菜单项被选中).
Exit
Case $Button1 ;更改IP地址
If GUICtrlRead($Combo1) = "本地连接" Then
$ConName = $NetworkAdapterInfo
MsgBox("1","a",$ConName)
$IpADD = GUICtrlRead($Input2)
$GateWay = GUICtrlRead($Input3)
$ConDNS2 = GUICtrlRead($Input6)
$SubMask = GUICtrlRead($Input5)
$ConDNS1 = GUICtrlRead($Input4)
MsgBox("1","a","")
MsgBox("1","wert","ip地址:"&$IpADD&@CRLF&"子网掩码:"&$SubMask&@CRLF&"网关地址:"&$GateWay&@CRLF&"首选DNS:"&$ConDNS1&@CRLF&"备用DNS:"&$ConDNS2&@CRLF&"都已更改")
If $OSVersion = "WIN_XP" Then
_CMD_SetLocalIP_XP($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
If$OSVersion = "WIN_7" Then
_CMD_SetLocalIP_WIN7($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
Exit
EndIf
Case $Button2
If GUICtrlRead($Combo1) = "本地连接" Then
MsgBox(1,"",IniRead($ScriptDir, "DHCP", "dhcp值", "NotFound"))
If IniRead($ScriptDir, "DHCP", "dhcp值", " ") = "True" Then
MsgBox("1","ss","asdfasdfasdfasdfasfd")
_DHCP_IP_SetLocalIP()
_DHCP_DNS_SetLocalIP()
EndIf
If IniRead($ScriptDir, "DHCP", "dhcp值", " ") = "False" Then
GUICtrlSetData($Input1,@ComputerName) ;修改指定控件的数据.
GUICtrlSetData($Input2,IniRead($ScriptDir, "本地连接", "ip地址", "NotFound"))
GUICtrlSetData($Input3,IniRead($ScriptDir, "本地连接", "网关地址", "NotFound"))
GUICtrlSetData($Input4,IniRead($ScriptDir, "本地连接", "首选DNS", "NotFound"))
GUICtrlSetData($Input5,IniRead($ScriptDir, "本地连接", "子网掩码", "NotFound"))
GUICtrlSetData($Input6,IniRead($ScriptDir, "本地连接", "备用DNS", "NotFound"))
$ConName = $NetworkAdapterInfo
$IpADD = GUICtrlRead($Input2)
$GateWay = GUICtrlRead($Input3)
$ConDNS1 = GUICtrlRead($Input4)
$SubMask = GUICtrlRead($Input5)
$ConDNS2 = GUICtrlRead($Input6)
MsgBox("1","sss","asdfasdfasdfasdfasfd")
MsgBox("1","wert","ip地址:"&$IpADD&@CRLF&"子网掩码:"&$SubMask&@CRLF&"网关地址:"&$GateWay&@CRLF&"首选DNS:"&$ConDNS1&@CRLF&"备用DNS:"&$ConDNS2&@CRLF&"都已还原初始状态")
If $OSVersion = "WIN_XP" Then
_CMD_SetLocalIP_XP($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
If$OSVersion = "WIN_7" Then
_CMD_SetLocalIP_WIN7($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
;_CMD_SetLocalIP($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
Exit
EndIf
EndIf
EndSwitch
WEnd
Func _NetworkAdapterInfo()
Local $colItems1 = ""
Local $objWMIService
Local $NetworkAdapterID = 0
Local $NetworkAdapterName = ""
Local $NetworkAdapterGateway = ""
Local $NetworkAdapterHostName = ""
Local $NetworkAdapterIPaddress = ""
Local $NetworkAdapterDNS1 = ""
Local $NetworkAdapterDNS2 = ""
Local $NetworkAdapterSubnet = ""
Local $NetworkAdapterMAC = ""
Local $NetworkAdapterNetConnectionID = ""
Local $NetworkAdapterNetConnectionStatus = ""
Local $NetworkAdapterInfo ;最高10块网卡.
$NetworkAdapterInfo = 0
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems1 = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus >0 ', "WQL", 0x30)
If IsObj($colItems1) Then
For $objItem In $colItems1
$NetworkAdapterName = $objItem.Description
If $NetworkAdapterName="" Then ContinueLoop
If StringInStr ($NetworkAdapterName,"vmware")=True Then ContinueLoop
$NetworkAdapterNetConnectionStatus = $objItem.NetConnectionStatus
$NetworkAdapterNetConnectionID = $objItem.NetConnectionID
If StringInStr ($NetworkAdapterNetConnectionID,"无线")=True Then ContinueLoop
$NetworkAdapterIndex = $objItem.Index
$NetworkAdapterMAC = $objItem.MACAddress
$NetworkAdapterID += 1
$NetworkAdapterInfo = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterName
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterNetConnectionStatus ;反回的值是2表示在线,7表示不在线。
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterNetConnectionID
MsgBox("1","3",$NetworkAdapterInfo[$NetworkAdapterID])
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterMAC
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterIndex
Local $colItems2 = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = "'& $NetworkAdapterIndex &'" ', "WQL", 0x30)
If IsObj($colItems2) Then
For $objItem2 In $colItems2
$NetworkAdapterIPaddress = $objItem2.IPAddress(0)
$NetworkAdapterDHCPEnabled = $objItem2.DHCPEnabled
$NetworkAdapterIPSubnet = $objItem2.IPSubnet(0)
$NetworkAdapterDefaultIPGateway = $objItem2.DefaultIPGateway(0)
$NetworkAdapterDNS1 = $objItem2.DNSServerSearchOrder(0)
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterDHCPEnabled
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterIPaddress
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterIPSubnet
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterDefaultIPGateway
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterDNS1
If UBound($objItem2.DNSServerSearchOrder)>1 Then
$NetworkAdapterDNS2 = $objItem2.DNSServerSearchOrder(1)
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterDNS2
EndIf
Next
EndIf
Next
Else
Return $NetworkAdapterInfo
EndIf
Return $NetworkAdapterInfo
_ArrayDisplay($NetworkAdapterInfo)
EndFunc ;==>_NetworkAdapterInfo
Func _CMD_SetLocalIP_WIN7($ConName, $IpADD, $SubMask, $GateWay, $ConDNS1,$ConDNS2)
If $SubMask <> "" Then $SubMask = "255.255.255.0"
If $ConName <> "" And $IpADD <> "" Then
RunWait(@ComSpec & ' /C netsh -c interface ip set address ' & '"' & $ConName & '"' & ' static ' & $IpADD & " " & $SubMask & " " & $GateWay, "", @SW_HIDE)
EndIf
If $ConDNS1 <> "" Then
RunWait(@ComSpec & ' /C netsh -c interface ip set dns ' & '"' & $ConName & '"' & ' static ' & $ConDNS1 & ' primary validate=no', "", @SW_HIDE)
EndIf
If $ConDNS2 <> "" Then
RunWait(@ComSpec & ' /C netsh -c interface ip add dns ' & '"' & $ConName & '" ' & $ConDNS2 & ' validate=no', "", @SW_HIDE)
EndIf
EndFunc ;==>_CMD_SetLocalIP
Func _CMD_SetLocalIP_XP($ConName, $IpADD, $SubMask, $GateWay, $ConDNS1,$ConDNS2)
If $SubMask <> "" Then $SubMask = "255.255.255.0"
If $ConName <> "" And $IpADD <> "" Then
RunWait(@ComSpec & ' /C netsh interface ip set address ' & '"' & $ConName & '"' & ' static ' & $IpADD & " " & $SubMask & " " & $GateWay & " " & ' none ',"", @SW_HIDE)
EndIf
If $ConDNS1 <> "" Then
RunWait(@ComSpec & ' /C netshinterface ip set dns ' & '"' & $ConName & '"' & ' static ' & $ConDNS1 & ' primary', "", @SW_HIDE)
EndIf
If $ConDNS2 <> "" Then
RunWait(@ComSpec & ' /C netshinterface ip add dns ' & '"' & $ConName & '" ' & $ConDNS2,"", @SW_HIDE)
EndIf
EndFunc ;==>_CMD_SetLocalIP
Func _DHCP_IP_SetLocalIP()
RunWait(@ComSpec & ' /C netsh interface ip set address ' & '"' & $NetworkAdapterInfo & '"' & ' source=dhcp ', "", @SW_HIDE)
EndFunc
Func _DHCP_DNS_SetLocalIP()
RunWait(@ComSpec & ' /C netsh interface ip set dns ' & '"' & $NetworkAdapterInfo & '"' & ' source=dhcp ', "", @SW_HIDE)
EndFunc
y1751
发表于 2011-12-2 20:38:03
楼主还是很辛苦的,不过就是少了点共享精神。谢谢lz的辛苦。
有些功能没什么用处,比如多网卡。要用工具肯定是要批量的。少数几个还不如手工改。所以我做的加上了根据mac修改ip。但是我做的界面实在不好看,呵呵
321ewq321
发表于 2011-12-5 22:51:39
鄙视这些没有任何介绍文件,看一眼就收费的楼主们!
流浪628
发表于 2011-12-7 17:40:45
流浪628
发表于 2011-12-7 17:42:12
改到这一步,就算是最后改完了。
流浪628
发表于 2011-12-7 17:44:11
回复 22# haijie1223
哈哈,哪段代码,我都修改了N次了。
流浪628
发表于 2011-12-9 10:04:35
回复 15# 兔子先生
我写这个是给公司写的,又不是专门写来玩的,当然怎么好用简洁怎么来呀!
woyun
发表于 2011-12-13 08:41:47
我去了 然后还不是代码,服了{:face (114):}
woyun
发表于 2011-12-14 07:46:48
看看除了常用的功能外,还多了什么,怎么个完整法。。{:face (361):}