Solved

IP Number to IP address

Posted on 2006-11-16
1
930 Views
Last Modified: 2008-01-09
I need a function that converts ip numer into IP address.

ipnum = 16777216*w + 65536*x + 256*y + z
where
IP Address = w.x.y.z
0
Comment
Question by:mxpoint
1 Comment
 
LVL 10

Accepted Solution

by:
bchoor earned 125 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()
        Dim IpAddress As New ArrayList

        For Each m As Match In Regex.Matches(IpNumber.ToString("x0").ToUpper(), "[\dA-F]{2}")
            IpAddress.Add(CType("&H" & m.Value, Integer))
        Next

        Return IpAddress.ToArray(GetType(System.Int32))
    End Function

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


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

        v = IpNumber >> 24
        IpAddress.Add(v)
        IpNumber = IpNumber - (v * 2 ^ 24)

        v = IpNumber >> 16
        IpAddress.Add(v)
        IpNumber = IpNumber - (v * 2 ^ 16)

        v = IpNumber >> 8
        IpAddress.Add(v)
        IpNumber = IpNumber - (v * 2 ^ 8)

        v = IpNumber
        IpAddress.Add(v)

        Return IpAddress.ToArray(GetType(System.Int32))
    End Function
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AutoHotkey ActiveX Component Error 8 72
Enable copy and pasting even when textbox is disabled 2 26
Help with LINQ and XML 10 27
Crystal reports vb.net 2 20
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now