7 Nisan 2012 Cumartesi

Long2IP


Visual Basic.Net

SQL' kayıt esnasında IP adresi Long olarak kayıt edilir. Long2IP ile bu değeri tekrar IP olarak ekrana basmak için basit bi fonksiyon... 



Public Function Long2Ip(ByVal ipLong)
    Dim ipA, ipB, ipC, ipD
    ipA = Fix(ipLong / 256 ^ 3)
    ipB = Fix((ipLong - ipA * 256 ^ 3) / 256 ^ 2)
    ipC = Fix((ipLong - (ipA * 256 ^ 3 + ipB * 256 ^ 2)) / 256)
    ipD = Fix(ipLong - ((ipA * 256 ^ 3) + (ipB * 256 ^ 2) + (ipC * 256)))
    ipadres = (255 + ipA) & "." & (255 + ipB) & "." & (255 + ipC) & "." & (256 + ipD)
    Return ipLong
End Function


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Long2Ip("-1407788077")
    MsgBox(ipadres)
End Sub

Hiç yorum yok: