GUICreate("获取计算机名", 300, 120)
$Label0 = GUICtrlCreateLabel("==============获取计算机名==============", 24, 10, 280, 17)
$Label1 = GUICtrlCreateLabel("请输入IP地址:", 24, 32, 90, 17)
$Input1 = GUICtrlCreateInput("", 115, 30, 150, 18)
GUICtrlSetData(-1, @IPAddress1)
$Label2 = GUICtrlCreateLabel("获取计算机名:", 24, 52, 90, 17)
$Input2 = GUICtrlCreateInput("", 115, 50, 150, 18)
GUICtrlSetState(-1, 144)
$btn = GUICtrlCreateButton("获取", 24, 85, 120, 22)
$btc = GUICtrlCreateButton("退出", 145, 85, 120, 22)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3, $btc
Exit
Case $btn
GUICtrlSetState($Input2, 144)
$ip = GUICtrlRead($Input1)
$b = StringRegExp($ip, "(((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?))", 3)
If @error <> 0 Then
MsgBox(0, 0, '请输入IP地址的正确格式')
Else
GUICtrlSetState($btn, 144)
GUICtrlSetData($Input2, '正在搜索,请稍候...')
TCPStartup()
$nHost = __TCPIpToName($b[0])
TCPShutdown()
If $nHost = '' Then
GUICtrlSetData($Input2, '未找到目标计算机')
Else
GUICtrlSetData($Input2, $nHost)
GUICtrlSetState($Input2, 80)
EndIf
GUICtrlSetState($btn, 80)
EndIf
EndSwitch
WEnd
Func __TCPIpToName($sIp, $iOption = Default, $hDll_Ws2_32 = Default)
Local $vbinIP, $vaDllCall, $vptrHostent, $vHostent, $sHostnames, $vh_aliases, $i
Local $INADDR_NONE = 0xffffffff, $AF_INET = 2, $sSeperator = @CR
If $iOption = Default Then $iOption = 0
If $hDll_Ws2_32 = Default Then $hDll_Ws2_32 = "Ws2_32.dll"
$vaDllCall = DllCall($hDll_Ws2_32, "long", "inet_addr", "str", $sIp)
If @error Then Return SetError(1, 0, "") ; inet_addr DllCall Failed
$vbinIP = $vaDllCall[0]
If $vbinIP = $INADDR_NONE Then Return SetError(2, 0, "") ; inet_addr Failed
$vaDllCall = DllCall($hDll_Ws2_32, "ptr", "gethostbyaddr", "long*", $vbinIP, "int", 4, "int", $AF_INET)
If @error Then Return SetError(3, 0, "") ; gethostbyaddr DllCall Failed
$vptrHostent = $vaDllCall[0]
If $vptrHostent = 0 Then
$vaDllCall = DllCall($hDll_Ws2_32, "int", "WSAGetLastError")
If @error Then Return SetError(5, 0, "") ; gethostbyaddr Failed, WSAGetLastError Failed
Return SetError(4, $vaDllCall[0], "") ; gethostbyaddr Failed, WSAGetLastError = @Extended
EndIf
$vHostent = DllStructCreate("ptr;ptr;short;short;ptr", $vptrHostent)
$sHostnames = __TCPIpToName_szStringRead(DllStructGetData($vHostent, 1))
If @error Then Return SetError(6, 0, $sHostnames) ; strlen/sZStringRead Failed
If $iOption = 1 Then
$sHostnames &= $sSeperator
For $i = 0 To 63 ; up to 64 Aliases
$vh_aliases = DllStructCreate("ptr", DllStructGetData($vHostent, 2) + ($i * 4))
If DllStructGetData($vh_aliases, 1) = 0 Then ExitLoop ; Null Pointer
$sHostnames &= __TCPIpToName_szStringRead(DllStructGetData($vh_aliases, 1))
If @error Then
SetError(7) ; Error reading array
ExitLoop
EndIf
Next
Return StringSplit(StringStripWS($sHostnames, 2), @CR)
Else
Return $sHostnames
EndIf
EndFunc ;==>__TCPIpToName
Func __TCPIpToName_szStringRead($iszPtr, $iLen = -1, $hDll_msvcrt = "msvcrt.dll")
Local $aStrLen, $vszString
If $iszPtr < 1 Then Return "" ; Null Pointer
If $iLen < 0 Then
$aStrLen = DllCall($hDll_msvcrt, "int:cdecl", "strlen", "ptr", $iszPtr)
If @error Then Return SetError(1, 0, "") ; strlen Failed
$iLen = $aStrLen[0] + 1
EndIf
$vszString = DllStructCreate("char[" & $iLen & "]", $iszPtr)
If @error Then Return SetError(2, 0, "")
Return SetError(0, $iLen, DllStructGetData($vszString, 1))
EndFunc ;==>__TCPIpToName_szStringRead
那个 _GUICtrlIpAddress_Set 函数貌似有问题(Au3版本3.3.1.1)