'
' Convert IP address point-to-point to decimal.
'
Public Shared Function dot2longip () Function Dot2longip ( Byval Dotip As String ) As Long
' Use regular expressions to check IP addresses
Dim Subip As String () = Split (Dotip, " . " )
' IP address = W. x. y. Z
' IP number = 16777216 * w + 65536 * x + 256 * Y + z
Dot2longip = 16777216 * Clng (Subip ( 0 )) + 65536 * Clng (Subip ( 1 )) + 256 * Clng (Subip ( 2 )) + Clng (Subip ( 3 ))
End Function
Public Shared Function longip2dot () Function Longip2dot ( Byval Longip As Long ) As String
' IP address = W. x. y. Z
' IP number = 16777216 * w + 65536 * x + 256 * Y + z
' W = int (IP number/16777216) % 256
' X = int (IP number/65536) % 256
' Y = int (IP number/256) % 256
' Z = int (IP number) % 256
Dim Dotip As String
Dim Subip As Integer
Subip = CINT (Fix (longip / 16777216) ) MoD 256
Dotip = CSTR (Subip) + " ."
Subip = CINT (Fix (longip / 65536) ) MoD 256
Dotip + = CSTR (Subip) + " ."
Subip = CINT (Fix (longip / 256) ) MoD 256
Dotip + = CSTR (Subip) + " ."
Subip = CINT (Fix (longip MoD 256) )
Dotip + = CSTR (Subip)
Return Dotip
End Function
In addition, ninputer: The method is indeed good, and the efficiency must be higher than the previous calculation method.
< Structlayout (layoutkind. Explicit ) > _
Public Structure ipconvert Structure Ipconvert
< Fieldoffset ( 0 ) > Public Longip As Long
< Fieldoffset ( 0 ) > Public Dotip0 As Byte
< Fieldoffset ( 1 ) > Public Dotip1 As Byte
< Fieldoffset ( 2 ) > Public Dotip2 As Byte
< Fieldoffset ( 3 ) > Public Dotip3 As Byte
End Structure
Note that the namespace system. runtime. interopservices must be introduced, and the longip type is indeed long, not integer.