IP地址解析成主机名失败
_TCPIpToName解析一个IP地址到主机名称,为什么解析不了。。我哪使用错了。#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <Inet.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 331, 80, 495, 472)
$input = GUICtrlCreateInput("119.75.217.56", 8, 16, 209, 21);百度IP
$Button1 = GUICtrlCreateButton("Button1", 240, 16, 73, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
TCPStartup()
$nameip = TCPNameToIP(GUICtrlRead($input))
$ipname = _TCPIpToName(GUICtrlRead($input))
If _isIP(GUICtrlRead($input)) Then
If @error Then
MsgBox(4096, "","错误")
Else
MsgBox(4096, "", $ipname)
EndIf
Else
MsgBox(0, "", $nameip)
EndIf
EndSwitch
WEnd
Func _isIP($ip)
Return StringRegExp($ip, "^(25|2|{1}{2}|{1}{1}|)\.(25|2|{1}{2}|{1}{1}||0)\.(25|2|{1}{2}|{1}{1}||0)\.(25|2|{1}{2}|{1}{1}|)$")
EndFunc ;==>_isIP
StringRegExp返回值是数组 本帖最后由 lpxx 于 2012-3-12 01:12 编辑
而且,貌似正则不对。
论坛有例子,参考一下。
#include <Array.au3>
$T0 = "119.75.217.56"
$Pattern = '((?:(?:25|2\d|?\d?\d)\.){3}(?:25|2\d|?\d?\d))'
$Result = StringRegExp($T0, $Pattern, 1)
If Not @error Then MsgBox(0, StringLen($Result), $Result)
_ArrayDisplay($Result, 1)
解析主机名你先测试
#include <array.au3>
#include <inet.au3>
Local $aResult
TCPStartup()
$sIp="127.0.0.1"
$aResult = _TCPIpToName($sIp, 1)
If @error Then
MsgBox(0, "_TCPIpToName()", "@error = " & @error & @LF & "@extended = " & @extended)
Else
MsgBox(0,0,$aResult)
EndIf
我就知道这些了,希望可以给你点参考。
页:
[1]