『楼 主』:
[原创]IP和整数互换[vbs版]
''''''''IP和整数互换 {s11ss 2007-12-9}''''''''
Option Explicit
Dim str,re,match,n(3),i,answer,q,r
str=InputBox("请输入IP或对应的整数:","IP和整数互换","127.0.0.1")
If str="" Then WScript.Quit
Set re = New RegExp
re.Global = True
re.IgnoreCase = True
re.MultiLine = false
'IP转整数:
re.Pattern = "^(\d{1,2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1,2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1,2}|[0-1]\d{2}|2[0-4]\d|25[0-5])\.(\d{1,2}|[0-1]\d{2}|2[0-4]\d|25[0-5])$"
If re.Test(str) Then
Set match=re.Execute(str)
For i=0 To 3
n(i)=CInt(match(0).Submatches(i))
answer=answer+n(i)*256^(3-i)
Next
InputBox vbcrlf&"IP:"&str&vbcrlf&vbcrlf&vbcrlf&"对应的整数为:","转换结果",answer
WScript.Quit
End If
'整数转IP:
re.Pattern="^\d+$"
If re.Test(str) Then
q=CLng(str)
answer=""
While q<>0
r=q Mod 256
q=q\256
If answer="" Then
answer=CStr(r)
Else
answer=CStr(r)&"."&answer
End if
Wend
InputBox vbcrlf&"整数:"&str&vbcrlf&vbcrlf&vbcrlf&"对应的IP为:","转换结果",answer
End If
此帖被 +8 点积分 点击查看详情 评分人:【 lxmxn 】 | 分数: +8 | 时间:2007-12-9 17:24 |
|
|