views:

86

answers:

1

so i have a code which gets me the ip address of a machine i am wroking on.

so if my gui is published on the server and i access it from my local machine it gives me tha address of my local machine and when i access the gui from the server itself it gives me the server address.. which is fine.

But when i put the gui on a VM server and run it from a VM server itself i dont get the ip address. this works fine if i access it from another machine but does not work only when accesing gui on VM server..

please help me out as i get this value ":::1"

here is my code:

        string ipaddress;
        //string ipaddress = Request.ServerVariables["LOCAL_ADDR"];
        string ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (ipaddress == "" || ipaddress == null)
        string ipaddress = Request.ServerVariables["REMOTE_ADDR"];
        Label5.Text = ipaddress;

thank you

+3  A: 

Well it actually does work. ":::1" is the IPv6 address for localhost similar to 127.0.0.1

Since you are accessing from the same machine, it doesn't go over the external network interface.

If you want to get IPv4 adress, run "ncpa.cpl" and disable IPV6 on your network adapters.

Vlad