Jobs
Author: Norm Garrett Date Submitted: 2/5/2002 Category: Internet Compatibility: VB 6 This code has been accessed 4520 times.
Email Yourself this snippet:
No declarations
Code
Public Function LongToIP(addr As Long) As String Dim HexAddr As String Dim bytes(4) As String Dim IPNodes(4) As String Dim x As Integer Dim y As Integer 'This function receives a long IP address and 'converts it to a valid string IP address 'Note that the long IP address is created by taking 'Each byte of the IP address and converting to hex 'in reverse order and then converting the resulting '4 bytes of hex to a decimal number 'Get the hex value of the long HexAddr = Hex$(addr) 'Add a leading zero to the first hex byte if needed If Len(HexAddr) = 7 Then HexAddr = "0" & HexAddr End If 'convert each hex byte value into a decimal string and 'put into the array in reverse order y = 4 For x = 1 To 8 Step 2 bytes(y) = Mid(HexAddr, x, 2) y = y - 1 Next x 'convert each hex byte string to a decimal address For x = 1 To 4 IPNodes(x) = LTrim(Str(Val("&H" & bytes(x)))) Next x 'convert the strings to an IP address LongToIP = "" For x = 1 To 4 If x < 4 Then LongToIP = LongToIP & IPNodes(x) & "." Else LongToIP = LongToIP & IPNodes(x) End If Next x End Function