Get public ip of the C # device

0

I'm trying to get the public ip of the team. In addition to additional information such as the type of browser and the location of the public IP obtained. One of my main questions is to know if there is a place where this information can be obtained and that it is reliable, or if there is another method of obtaining it. I was able to get the ip as follows:

HttpWebRequest wq= (HttpWebRequest)WebRequest.Create("http://bot.whatismyipaddress.com"); HttpWebResponse wr = (HttpWebResponse)wq.GetResponse(); StreamReader sr = new StreamReader(wr.GetResponseStream(), System.Text.Encoding.UTF8); IPAddress ip = IPAddress.Parse(sr.ReadToEnd()); sr.Close(); wr.Close();

    
asked by Eduardo 22.12.2017 в 02:45
source

1 answer

1
using System;
using System.Net;

public class Program
{
    public static void Main()
    {
    string externalip = new WebClient().DownloadString("http://icanhazip.com");            
    Console.WriteLine(externalip);
    }
}

link

Requests to APIs are made without a browser interface. Keep in mind that if your IP is dynamically configured you will get different results over time. Other ways to obtain it (through the command console):

curl http://ipinfo.io/ip

wget -qO- http://bot.whatismyipaddress.com

For the location you can try this API:

curl http://ip-api.com/json

To get the browser from which you are running Javascript code: link

    
answered by 22.12.2017 / 10:36
source