VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts a long integer IP address into a string IP address (opposite of AddressStringToLong functi

by Norm Garrett (1 Submission)
Category: Internet/HTML
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 2nd May 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts a long integer IP address into a string IP address (opposite of AddressStringToLong function found in many Ping programs)

Rate Converts a long integer IP address into a string IP address (opposite of AddressStringToLong functi



    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

Download this snippet    Add to My Saved Code

Converts a long integer IP address into a string IP address (opposite of AddressStringToLong functi Comments

No comments have been posted about Converts a long integer IP address into a string IP address (opposite of AddressStringToLong functi. Why not be the first to post a comment about Converts a long integer IP address into a string IP address (opposite of AddressStringToLong functi.

Post your comment

Subject:
Message:
0/1000 characters