Convert IPv6 Address to IP numbers


/ Published in: VB.NET
Save to your folder(s)

Use the code below to convert the IP address of your web visitors and lookup for their geographical location, e.g. country, state, city, latitude/longitude, ZIPs, timezone and so on. Free database can be downloaded at http://lite.ip2location.com.


Copy this code and paste it in your HTML
  1. ''' <summary>
  2. ''' Convert IPV6 Address to IP Number
  3. ''' Free geolocation database can be downloaded at:
  4. ''' http://lite.ip2location.com/
  5. ''' </summary>
  6.  
  7. Dim strIP As String = "2404:6800:4001:805::1006"
  8. Dim address As System.Net.IPAddress
  9. Dim ipnum As System.Numerics.BigInteger
  10.  
  11. If System.Net.IPAddress.TryParse(strIP, address) Then
  12. Dim addrBytes() As Byte = address.GetAddressBytes()
  13.  
  14. If System.BitConverter.IsLittleEndian Then
  15. Dim byteList As New System.Collections.Generic.List(Of Byte)(addrBytes)
  16. byteList.Reverse()
  17. addrBytes = byteList.ToArray()
  18. End If
  19.  
  20. If addrBytes.Length > 8 Then
  21. 'IPv6
  22. ipnum = System.BitConverter.ToUInt64(addrBytes, 8)
  23. ipnum <<= 64
  24. ipnum += System.BitConverter.ToUInt64(addrBytes, 0)
  25. Else
  26. 'IPv4
  27. ipnum = System.BitConverter.ToUInt32(addrBytes, 0)
  28. End If
  29. End If

URL: http://lite.ip2location.com/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.