تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
القيام بعملية التحويل IP to Long و Long to IP لعناوين ال IP
#1
كاتب الموضوع : Boutemine Oualid

السلام عليكم و رحمة الله و بركاته

كود :
Public Shared Function IPToLong(ByVal ipAddress As String) As Long
Try
Dim ip As System.Net.IPAddress = Net.IPAddress.Parse(ipAddress)
Return (CLng(ip.GetAddressBytes(0)) << 24) Or (CInt(ip.GetAddressBytes(1)) << 16) Or (CInt(ip.GetAddressBytes(2)) << 8) Or ip.GetAddressBytes(3)
Catch ex As Exception
Return 0
End Try

End Function

Public Shared Function LongToIP(ByVal ipAddress As Long) As String
Try
Dim tmpIP As New Net.IPAddress(ipAddress)
Dim bytes() As Byte = tmpIP.GetAddressBytes()
Array.Reverse(bytes)
Dim addr As Long = CLng(BitConverter.ToUInt32(bytes, 0))
Return New Net.IPAddress(addr).ToString()
Catch ex As Exception
Return ex.Message
End Try
End Function
'How to use
Dim IPFromLong As Long = IPToLong("127.0.0.1") ' return 2130706433
Dim IPFromString As String = LongToIP(2130706433) ' return "127.0.0.1"
}}}}
تم الشكر بواسطة:


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم