منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
القيام بعملية التحويل IP to Long و Long to IP لعناوين ال IP - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : الأقسام التعليمية - المنتدى القديم (http://vb4arb.com/vb/forumdisplay.php?fid=90)
+--- قسم : مكتبة أكواد المنتدى (http://vb4arb.com/vb/forumdisplay.php?fid=111)
+---- قسم : مكتبة أكواد لغات الويب (http://vb4arb.com/vb/forumdisplay.php?fid=119)
+---- الموضوع : القيام بعملية التحويل IP to Long و Long to IP لعناوين ال IP (/showthread.php?tid=6417)



القيام بعملية التحويل IP to Long و Long to IP لعناوين ال IP - RaggiTech - 17-10-12

كاتب الموضوع : 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"