请问有没有把long和IP地址两种格式进行相互转换的函数?

eternall 2003-12-10 11:50:32
rt
3Q
...全文
15 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
eternall 2003-12-10
比如257转换为IP地址就是 0.0.1.1
回复
northwolves 2003-12-10
????
回复
northwolves 2003-12-10
数太大可能会溢出:
Private Sub Command1_Click()
MsgBox iptolong("0.250.1.1")
MsgBox longtoip(257000)
End Sub
Function iptolong(ByVal ip As String) As Long
Dim temp
temp = Split(ip, ".")
iptolong = 0
For i = 0 To 3
iptolong = iptolong + CLng(temp(i)) * 256 ^ (3 - i)
Next
End Function
Function longtoip(ByVal iptolong As Long) As String
Dim temp(3)
For i = 3 To 0 Step -1
temp(i) = iptolong Mod 256
iptolong = iptolong \ 256
Next
longtoip = Join(temp, ".")
End Function
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告