Как найти публичный IP-адрес клиента в Интернете в C#?
I want the client public ip in c# i have used the below code get the public ip of client but code is getting only hosted server IP only not getting client's public ip how to get the Public ip of client.
these code getting only hosted server ip.
Что я уже пробовал:
static string GetIPAddress() { String address = ""; WebRequest request = WebRequest.Create("http://checkip.dyndns.org/"); using (WebResponse response = request.GetResponse()) using (StreamReader stream = new StreamReader(response.GetResponseStream())) { address = stream.ReadToEnd(); } int first = address.IndexOf("Address: ") + 9; int last = address.LastIndexOf("</body>"); address = address.Substring(first, last - first); return address; }
public string GetIPAddress() { try { // string address; address = (new WebClient()).DownloadString("http://checkip.dyndns.org/"); address = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")) .Matches(address)[0].ToString(); return address; } catch { return null; } }