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

eternall 2003-12-10 11:50:32
rt
3Q
...全文
76 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧