include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <ACN_NET.au3>
#include <Inet.au3>
Local $msg
Dim $net
GUICreate("My GUI") ;
GUISetState(@SW_SHOW) ;
GUICtrlCreateGroup("信息区",10,100,300,200)
GUICtrlCreateLabel("IP地址 :",20,120,-1,-1)
$hIP_Input = GUICtrlCreateInput(" ", 120, 120, 150, -1)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetData($hIP_Input, @IPAddress1)
GUICtrlCreateLabel("子网掩码 :",20,140,-1,-1)
$net_Input =GUICtrlCreateInput(" ", 120, 140, 150, -1)
net()
GUICtrlSetData($net_Input,$net)
GUICtrlCreateLabel("默认网关 :",20,160,-1,-1)
$hmask_Input = GUICtrlCreateInput(" ", 120, 160, 150, -1)
GUICtrlSetData($hmask_Input, _Gateway())
GUICtrlCreateLabel("MAC地址 :",20,180,-1,-1)
$hmac_Input = GUICtrlCreateInput("",120,180,150,-1)
GUICtrlSetData($hmac_Input,_API_Get_NetworkAdapterMAC(@IPAddress1))
GUICtrlCreateLabel("公网IP地址 :",20,200,-1,-1)
$pip_Input = GUICtrlCreateInput("",120,200,150,-1)
GUICtrlSetData($pip_Input,public_ip())
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func _Gateway()
Dim $IPGateway
Dim $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Dim $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
For $objItem In $colItems
$IPGateway = $objItem.DefaultIPGateway(0)
If StringInStr($IPGateway, ".") > 0 Then ExitLoop
Next
Return StringRegExpReplace($IPGateway, '(\d+\.){12}', '')
EndFunc ;==>_Gateway
Func public_ip()
Local $source = _INetGetSource("http://ip.qq.com")
Local $aIP = StringRegExp($source, '您当前的IP为.*?(\d[\d.]+)', 3, 1)
If Not @error Then
Return $aIP[0]
Else
Return 0
EndIf
EndFunc
Func net()
Dim $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Dim $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
For $objItem In $colItems
$net =$objItem.IPSubnet(0)
Next
EndFunc ;==>_Gateway