函数参考


_TCPIpToName

解析一个IP地址到主机名称

#include <Inet.au3>
_TCPIpToName($sIp [,$iOption = 0 [, $hDll_Ws2_32 = "Ws2_32.dll"]])

参数

$sIp 带点的IP(v4)地址格式.
$iOption [可选参数] 默认(Default) = 0
0 = 返回一个字符串主机名称
1 = 返回数组 (参考说明)
$hDll_Ws2_32 [可选参数] Ws2_32.dll 的句柄.

返回值

成功: 返回主机名或数组(见备注)
失败: ""
@Error: 0 = 无错误.
1 = inet_addr DllCall 失败
2 = inet_addr 失败
3 = gethostbyaddr DllCall 失败
4 = gethostbyaddr 失败, WSAGetLastError = @Extended
5 = gethostbyaddr 失败, WSAGetLastError 失败
6 = strlen/sZStringRead 失败
7 = 读取别名数组时错误

注意/说明

成功调用 WSAStartup (由 TCPStartup 完成) 是必需的.
如果 $iOption = 1 则返回如下格式的数组:
    $aResult[0] = 元素数量
    $aResult[1] = "主机名称"
    $aResult[2] = "别名 1"
    $aResult[3] = "别名 2"
    ...

相关

TCPStartup, TCPNameToIP

示例/演示


#include <Array.au3>
#include <Inet.au3>

Global $aResult, $sResult, $sIP

; 示例 1

TCPStartup()
$sIP = TCPNameToIP("hiddensoft.com")
$sResult = _TCPIpToName($sIP)
If @error Then
    MsgBox(4096, "_TCPIpToName()", "@error = " & @error & @LF & "@extended = " & @extended)
Else
    MsgBox(4096, "hiddensoft.com really is:", $sResult)
EndIf

; 示例 2

TCPStartup()
$sIP = _GetIP()
$aResult = _TCPIpToName($sIP, 1)
If @error Then
    MsgBox(4096, "_TCPIpToName()", "@error = " & @error & @LF & "@extended = " & @extended)
Else
    _ArrayDisplay($aResult, "Local Hostname(s)")
EndIf