Skip to main content

Posts

Showing posts with the label Getting Public IP address of a computer machine

How to Get Public IPv4 Address Using C#

In this article, we will see the multiple examples to get the public IP Address of a computer using C# . You should check out the docs . Example 1, static   string   GetPublicIPAddress () {      String   address  =  "" ;      WebRequest   request  =  WebRequest . Create ( "http://checkip.dyndns.org/" );      using  ( WebResponse   response  =  request . GetResponse ())      using  ( System . IO . StreamReader   stream  =  new   System . IO . StreamReader ( response . GetResponseStream ()))     {          address  =  stream . ReadToEnd ();     }      int   first  =  address . IndexOf ( "Address: " ) +  9 ;      int   last  ...