Method 1:
/// <Summary>
/// Obtain the logon IP Address
/// </Summary>
/// <Returns> </returns>
String getip ()
{
// You can use the Proxy Server
String userip = request. servervariables ["http_x_forwarded_for"];
If (userip = NULL | userip = "")
{
// No proxy server. If a proxy server obtains the IP address of the proxy server
Userip = request. servervariables ["remote_addr"];
}
Return userip;
}
Method 2: (this method obtains the IP address of the server)
// Using system. NET is required;
String hostname = DNS. gethostname (); // server user name
Response. Write ("hostname:" + hostname );
IPaddress [] address = DNS. gethostaddresses (hostname); // obtain the Server IP address list. The first IP address is address [0].
Ipendpoint = new ipendpoint (Address [0], 1234 );
Response. Write ("Address:" + ipendpoint. Address. tostring (); // output IP Address: 192.168.0.210, not 127.0.0.1
Response. Write ("port:" + ipendpoint. Port. tostring (); // output 1234
Response. Write ("endpoint:" + ipendpoint. tostring (); // The output is 192.168.0.210: 1234.