|
发表于 2016-2-25 08:46:49
|
显示全部楼层
回复 1# xia_xia
这样试试:
#include <AutoItConstants.au3>
#include <Array.au3>
#include <JY_IPget.au3>
Global Const $__WinINet_sDLL = "wininet.dll"
Global $__WinINet_hDLL = $__WinINet_sDLL
Global $wangka1, $mac, $DNS1
If _WinINet_InternetGetConnectedState() Then
MsgBox(0, True, "己联网!!!",3)
_WinINet_InternetGetConnectedStateaa()
Else
MsgBox(0, False, "断网!!!",5)
EndIf
Exit
Func _WinINet_InternetGetConnectedState()
Local $tFlags = DllStructCreate("dword")
Local $avResult = DllCall($__WinINet_hDLL,"bool", "InternetGetConnectedState", "ptr", DllStructGetPtr($tFlags),"dword", 0 )
If @error Then Return SetError(1, 0, False)
Return SetError(0, DllStructGetData($tFlags, 1), $avResult[0] <> 0)
EndFunc ;==>_WinINet_InternetGetConnectedState
Func _WinINet_InternetGetConnectedStateaa()
WMI()
For $i = 0 To UBound($wangka1) - 1
For $o = 0 To UBound($mac) - 1
Local $Chua4 = StringTrimLeft($DNS1[$o], 1)
Next
Next
$IP = JY_ipGet()
MsgBox(0, "网络地址:","外网IP地址: "&$IP &@CRLF &"无线网络IP:"&$Chua4)
EndFunc ;==>
Func WMI()
Local $dnsa1
$sMesStr = ""
$net = ""
$oLocator = ObjCreate("WbemScripting.SWbemLocator")
$oService = $oLocator.ConnectServer
$oClassSet = $oService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID IS NOT NULL")
For $oClass In $oClassSet
If @error Then ExitLoop
$sMesStr = $sMesStr & "连接名:“" & $oClass.NetConnectionID() & "”" & @CRLF & _
"网卡名: “" & $oClass.Name & "”" & @CRLF
Next
$oClassSet = ""
$oClass = ""
$oService = ""
$oLocator = ""
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", 0x10 + 0x20)
For $objItem In $colItems
;"网卡名:" & $objItem.Description & "”" & @CRLF & _
If @error Then ExitLoop
$net = $net & "ip地址: “:" & $objItem.IPAddress(0) & "”" & @CRLF & _
"mac地址: “" & $objItem.MACAddress & "”" & @CRLF & _
"首选dns: “:" & $objItem.DNSServerSearchOrder(0) & "”" & @CRLF ;& _
Next
$wangka1 = StringRegExp($sMesStr, "(?<=网卡名: “)[^”]+", 3)
$DNS1 = StringRegExp($net, "(?<=首选dns: “)[^”]+", 3)
$mac = StringRegExp($net, "(?<=mac地址: “)[^”]+", 3)
EndFunc ;==>WMI |
|