Find Public and Remote IP in C#

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