Capture IP and local machine name

Asked

Viewed 1,749 times

1

I need to get the ip and name of the client’s local machine in case the user who will be accessing my system.

My system is hosted on the network system and database. The commands I have used so far I get the server name and the server ip, but I need to know that the user is accessing the system from inside our office.

MYSQL database, I’ve used several commands, but already deleted I’ll put the last two I’m using below:

string[] computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_host"]).HostName.Split(new Char[] { '.' });
        String ecn = System.Environment.MachineName;                                  
        string vNomeMaquina = computer_name[0].ToString();


    string Ip;

        System.Net.IPHostEntry v_ipMaquina = System.Net.Dns.Resolve(vNomeMaquina);
        System.Net.IPAddress[] address = v_ipMaquina.AddressList;
        for (int i = 0; i < address.Length; i++) //ciclo q escreve o ip
            Ip = (Ip + address[i]);
  • Any language ?

  • 1

    Asp.net is not language. It is C#?

  • infome which database you are using, and there you speak C# Asp.net, but you need to know more. It could be webforms, it could be mvc or even Asp.net core. If possible, place an excerpt of your code where you would like to take this data

  • I have now used the following commands: For the host name = System.Net.Dns.Gethostentry(Request.Servervariables["remote_host"]). Hostname; and gave this result = b39f88fe.virtua.com.br

  • and used the command, public Static string Getpublicip() { 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 = Split(':'); string a2 = a[1]. Substring(1); string[] A3 = a2.Split('<'); string A4 = A3[0]; Return A4; }

  • ip = Getpublicip(); and the result is this = 187.84.230.84

Show 1 more comment

1 answer

1

You can access the user’s IP through HttpContext with the following code:

HttpContext.Current.Request.UserHostAddress

Now the name of the local machine through C# is not possible for security reasons.

  • Thank you Leonardo, this command takes the IP of the provider tested here now and took from my Net provider.

  • Ahh you want the local IP too?

  • This Leandro the local IP and if possible the name of the local machine also.

  • OK John, I’ll see if I can find a solution to your case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.