ipAddrInt, ipAddrStr in VBscript / VBA / VB6

Function ipAddrInt(ip)
    Dim a, tmp
    a = Split(ip, ".", 4)
    tmp = a(0) * 16777216# + a(1) * 65536 + a(2) * 256 + a(3) * 1
    ipAddrInt = tmp
End Function


Function ipAddrStr(i)
    Dim s, tmp
    s = Right(String(8, "0") & Hex(i), 8)
    tmp = CLng("&H" & Mid(s, 1, 2)) & "." & CLng("&H" & Mid(s, 3, 2)) & "." & CLng("&H" & Mid(s, 5, 2)) & "." & CLng("&H" & Mid(s, 7, 2))
    ipAddrStr = tmp
End Function

This entry was posted in Uncategorized, VBasic and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s