Convert long address to IP address

By | 2006-04-19

Converts a long address (2220112843) to it’s IP address (203.59.84.132)

Original Author: Wayne D

Returns

Example:
Result = IPToString(2220112843#)

API Declarations

Type MyLong
Value As Long
End Type
Type MyIP
A As Byte
B As Byte
C As Byte
D As Byte
End Type

Code

Function IPToString(Value As Double) As String
  Dim l As MyLong
  Dim i As MyIP
  l.Value = DoubleToLong(Value)
  LSet i = l
  IPToString = i.A & "." & i.B & "." & i.C & "." & i.D
End Function
Function DoubleToLong(Value As Double) As Long
  If Value <= 2147483647 Then
    DoubleToLong = Value
  Else
    DoubleToLong = -(4294967296# - Value)
  End If
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.