< %@ Page language="c#" % >< % Response.ContentType = "text/plain"; Response.Write( Request.UserHostAddress.ToString() ); % >getip.cs (command line example program)
using System; using System.IO; using System.Net; public class GetIpApp { static void Main() { WebClient client = new WebClient(); try { string strMyIp = client.DownloadString( "http://localhost/getip.aspx" ); Console.WriteLine( "IP Address is: {0}", strMyIp ); } catch( Exception ex ) { Console.WriteLine( ex.ToString() ); } } }If you were to try this on your own PC (as I've written) you'd get 127.0.0.1 as the IP address but on a remote server the firewall's IP would come back.