Find Public IP of System in C#
Namespace - using system.NET
- string url = "http://checkip.dyndns.org";
- System.Net.WebRequest req = System.Net.WebRequest.Create(url);
- System.Net.WebResponse resp = req.GetResponse();
- System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
- string response = sr.ReadToEnd().Trim();
- string[] a = response.Split(':');
- string a2 = a[1].Substring(1);
- string[] a3 = a2.Split('<');
- string publicip = a3[0].ToString();
Find Remote IP of system in C# - String hostName = System.Net.Dns.GetHostName();
- IPHostEntry localIpAddresses = Dns.GetHostEntry(hostName);
- string localip = localIpAddresses.AddressList[1].ToString();