找回密码
 加入
搜索
查看: 1945|回复: 3

[AU3基础] IP地址解析成主机名失败

[复制链接]
发表于 2012-3-12 00:24:00 | 显示全部楼层 |阅读模式
_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[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$")
EndFunc   ;==>_isIP

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-3-12 00:56:39 | 显示全部楼层
StringRegExp返回值是数组
发表于 2012-3-12 01:11:32 | 显示全部楼层
本帖最后由 lpxx 于 2012-3-12 01:12 编辑

而且,貌似正则不对。
论坛有例子,参考一下。

#include <Array.au3>
$T0 = "119.75.217.56"
$Pattern = '((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))'
$Result = StringRegExp($T0, $Pattern, 1)
If Not @error Then MsgBox(0, StringLen($Result[0]), $Result[0])
_ArrayDisplay($Result, 1)
发表于 2012-3-12 01:39:43 | 显示全部楼层
解析主机名你先测试

#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[1])
EndIf



我就知道这些了,希望可以给你点参考。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-17 09:44 , Processed in 0.085811 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表