#include #include #include #include Global Const $head = "Set IP address v1.0" Global $IpIs[6] , $IpSet[6] , $Sub[6], $Gat[6] , $Dhcp[6] , $SetIp[6] , $NetworkCards , $LanInfo[6][10] ; [0-5][0-9] Global $NameCard[20] , $FolderReg[20] , $Descripstion[20] , $ServiceName[20] , $StoredIpSet[6] , $lastIpSet[6] , $l , $i , $j _LanInfo() $GUI_SET=GuiCreate($head, $LanInfo[0][0]*270, 270,-1, -1 ); step 270 For $i = 1 To $LanInfo[0][0] ; --- Group ----- GuiCtrlCreateGroup($LanInfo[$i][2], 10+(($i-1)*270), 10, 250, 210) ; --- Labals ---- GuiCtrlCreateLabel("MAC Address : "& $LanInfo[$i][3], 20+(($i-1)*270), 40, 200, 20) GuiCtrlCreateLabel("Current IP :", 20+(($i-1)*270), 70, 70, 20) GuiCtrlCreateLabel("IP :", 20+(($i-1)*270), 130, 60, 20) GuiCtrlCreateLabel("Subnet :", 20+(($i-1)*270), 160, 60, 20) GuiCtrlCreateLabel("Gateway :", 20+(($i-1)*270), 190, 60, 20) ; --- Settings IP ---- $IpSet[$i]= _GUICtrlIpAddress_Create ($GUI_SET, 100+(($i-1)*270), 130, 140, 20) $Sub[$i] = _GUICtrlIpAddress_Create ($GUI_SET, 100+(($i-1)*270), 160, 140, 20) $Gat[$i] = _GUICtrlIpAddress_Create ($GUI_SET, 100+(($i-1)*270), 190, 140, 20) ; --- Actual IP ---- $IpIs[$i] = _GUICtrlIpAddress_Create ($GUI_SET, 100+(($i-1)*270), 70, 140, 20, -1,0x0800) _GUICtrlIpAddress_Set ($IpIs[$i], $LanInfo[$i][4]) Next For $i = 1 To $LanInfo[0][0] ; --- Radios ---- $Dhcp[$i] = GuiCtrlCreateRadio("DHCP", 160+(($i-1)*270), 100, 70, 20) $SetIp[$i] = GuiCtrlCreateRadio("Set manually", 40+(($i-1)*270), 100, 80, 20) ; $StoredIpSet[$i] = "" ; a record of the last ip value Next ; --- buttons ---- $Refresh = GuiCtrlCreateButton("Refresh", ((($LanInfo[0][0]*270)*25)/100 -50), 235, 60, 20 ,$BS_FLAT) $Set_IP = GuiCtrlCreateButton("Set IP", ((($LanInfo[0][0]*270)*50)/100) -30, 235, 60, 20,BitOR($BS_DEFPUSHBUTTON,$BS_FLAT)) $Exit = GuiCtrlCreateButton("Exit", ((($LanInfo[0][0]*270)*75)/100) -10, 235, 60, 20, $BS_FLAT) GuiSetState() While 1 $msg = GuiGetMsg() For $i = 1 to $LanInfo[0][0] Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit ;exit _exit() Case $msg = $Refresh ;refresh the IP and clear all _Refresh() ExitLoop Case GUICtrlRead ($Dhcp[$i]) = 1 And $Set_IP = $msg RunWait(@ComSpec & " /c netsh interface ip set address "&chr(34)& $LanInfo[$i][2] &chr(34)&" dhcp", "", @SW_HIDE) MsgBox (64, "Done", "Your "& $LanInfo[$i][2] &" is now in DHCP !") _Refresh() ExitLoop Case GUICtrlRead ($SetIp[$i]) = 1 And $Set_IP = $msg $Ipi = _GUICtrlIpAddress_Get ( $IpSet[$i] ) $Subi = _GUICtrlIpAddress_Get ( $Sub[$i] ) $Gati = _GUICtrlIpAddress_Get ( $Gat[$i]) RunWait(@ComSpec & " /c netsh interface ip set address "&chr(34)& $LanInfo[$i][2] &chr(34)&" static " _ & $Ipi & " "& $Subi & " "& $Gati & " 0", "", @SW_HIDE) MsgBox (64, "Done", "Your "& $LanInfo[$i][2] &" is now Set !") _Refresh() ExitLoop Case Not( _GUICtrlIpAddress_IsBlank ( $IpSet[$i] ) ) If GUICtrlRead($SetIp[$i],$GUI_UNCHECKED) And $l=0 Then $l = 1 GUICtrlSetState ($SetIp[$i],$GUI_CHECKED) EndIf _GUICtrlIpAddress_Set ($Sub[$i], "255.255.255.0") $lastIpSet[$i] = _GUICtrlIpAddress_Get ( $IpSet[$i] ) If $lastIpSet[$i] <> $StoredIpSet[$i] Then _GUICtrlIpAddress_Set ($Gat[$i], $lastIpSet[$i]) $StoredIpSet[$i] = $lastIpSet[$i] EndIf Case Else ;;; EndSelect Next WEnd Func _Refresh() _LanInfo() $i=0 $l=0 For $i = 1 To $LanInfo[0][0] GUICtrlSetState ($Dhcp[$i],$GUI_UNCHECKED) GUICtrlSetState ($SetIp[$i],$GUI_UNCHECKED) _GUICtrlIpAddress_ClearAddress ($IpSet[$i]) _GUICtrlIpAddress_ClearAddress ($Sub[$i]) _GUICtrlIpAddress_ClearAddress ($Gat[$i]) _GUICtrlIpAddress_Set ($IpIs[$i], $LanInfo[$i][4]) Next EndFunc Func _LanInfo() Local $mess _ComputerGetNetworkCards($NetworkCards) $j=0 $i=0 If @error Then MsgBox(0,"Error", "An error has been encounted please try again !") _exit() EndIf For $i = 1 To $NetworkCards[0][0] ; Take the Name of the cards of the PC If StringLeft ( $NetworkCards[$i][23], 3 ) = "PCI" Then $j+=1 $NameCard[$j] = $NetworkCards[$i][0] ;Name $LanInfo[$j][1]=$NetworkCards[$i][4] ;Description $LanInfo[$j][2]=$NetworkCards[$i][19] ;Net Connection ID $LanInfo[$j][3]=$NetworkCards[$i][15] ;MAC Address $LanInfo[$j][5]=$NetworkCards[$i][20] ;Net Connection Status EndIf Next $LanInfo[0][0]= $j $i=0 $j=0 For $i= 1 to $NetworkCards[0][0]; Find the "Card ID" ($ServiceName[$i]) in the Reg then Find The IP according to the "Card ID" $FolderReg[$i] = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards", $i) If @error <> 0 then ExitLoop $Descripstion[$i] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $FolderReg[$i] , "Description") For $j = 1 To $LanInfo[0][0] If $LanInfo[$j][5]<>2 Then ; if not connected $LanInfo[$j][4]="0.0.0.0" ExitLoop EndIf If $Descripstion[$i] = $NameCard[$j] Then $ServiceName[$i] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $FolderReg[$i] , "ServiceName") If RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $ServiceName[$i],"EnableDHCP") = 1 Then $LanInfo[$j][4]= RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $ServiceName[$i], "DhcpIPAddress") Else $LanInfo[$j][4]= RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $ServiceName[$i], "IPAddress") EndIf ;MsgBox (0, "ddd", $ServiceName[$i]& " : "&$NameCard[$j]) EndIf Next Next EndFunc Func _exit() For $i = 250 To 0 Step -10 WinSetTrans($head,"",$i ) Sleep(10) Next Exit EndFunc