get,public,ip,address

Mark 7/27/2016 0

this c# code will return you your public ip address

C#
 public static string GetPublicIP()
 {
            String direction = "";
            WebRequest request = WebRequest .Create("http://checkip.dyndns.org/" );
            using ( WebResponse response = request.GetResponse())
            using ( StreamReader stream = new StreamReader(response.GetResponseStream()))
            {
                direction = stream.ReadToEnd();
            }

            //Search for the ip in the html
            int first = direction.IndexOf( "Address: ")   9;
            int last = direction.LastIndexOf( "</body>");
            direction = direction.Substring(first, last - first);

            return direction;
 }
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments