x
Solved

# IP Number to IP address

Posted on 2006-11-16
Medium Priority
966 Views
I need a function that converts ip numer into IP address.

ipnum = 16777216*w + 65536*x + 256*y + z
where
0
Question by:mxpoint
1 Comment

LVL 10

Accepted Solution

bchoor earned 375 total points
ID: 17963112
I'm pretty sure there are several other ways this can be done --

you can just shift, multiply and subtract

w = ipnum >> 24
ipnum = ipnum - (w * 2^24)
x = ipnum >> 16
ipnum = ipnum - (x * 2^16)
I posted an example at the bottom of this post
and so forth

or Maybe something like this
Public Function IpNumberToIpAddress(ByVal IpNumber As Int64) As Integer()

For Each m As Match In Regex.Matches(IpNumber.ToString("x0").ToUpper(), "[\dA-F]{2}")
Next

End Function

Usage:
{Length=4}
(0): 192
(1): 168
(2): 0
(3): 1

Public Function IpNumberToIpAddress2(ByVal IpNumber As Int64) As Integer()
Dim v As Integer = 0

v = IpNumber >> 24
IpNumber = IpNumber - (v * 2 ^ 24)

v = IpNumber >> 16
IpNumber = IpNumber - (v * 2 ^ 16)

v = IpNumber >> 8
IpNumber = IpNumber - (v * 2 ^ 8)

v = IpNumber

End Function
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.