Last Comment

Calendar

July 2010
SunMonTueWedThuFriSat
 << < > >>
    123
45678910
11121314151617
18192021222324
25262728293031

Who's Online?

Member: 0
Visitor: 1

Announce

rss Syndication

03 Dec 2007 - 07:07:39 am
IP address to long and Long value to IP address string
this methods are depricated from framework 2.0 but still we need way to do this...so this is the way...

public static uint IPAddressToLong(string IPAddr)
        {
            IPAddress oIP = IPAddress.Parse(IPAddr);
            byte[] byteIP = oIP.GetAddressBytes();


            uint ip = (uint)byteIP[0] << 24;
            ip += (uint)byteIP[1] << 16;
            ip += (uint)byteIP[2] << 8;
            ip += (uint)byteIP[3];

            return ip;
        }

        public static string LongToIPAddress(uint ipLong)
        {
            //string ipAddress = string.Empty;
            byte[] addByte = new byte[4];

            addByte[0] = (byte)((ipLong >> 24) & 0xFF);
            addByte[1] = (byte)((ipLong >> 16) & 0xFF);
            addByte[2] = (byte)((ipLong >> 8) & 0xFF);
            addByte[3] = (byte)((ipLong >> 0) & 0xFF);

            return addByte[0].ToString() + "." + addByte[1].ToString() + "." + addByte[2].ToString() + "." + addByte[3].ToString();
        }
justchirag · 112 views · 0 comments
Categories: Functions
Tags: Tags IPAddress

Permanent link to full entry

http://patelslab.yourliveblog.com/Patel-s-Lab-b1/IP-address-to-long-and-Long-value-to-IP-address-string-b1-p17.htm

Comments

No Comment for this post yet...


Leave a comment

New feedback status: Awaiting moderation





Your URL will be displayed.

 
Please enter the code written in the picture.


Comment text

Options
   (Set cookies for name, email and url)