4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by aspproject
0

HttpContext.Current.Request.UserHostAddress

This doesn't attempt to take into account proxies. For that, you can use Request.ServerVariables["HTTP_X_FORWARDED_FOR"]. However, make sure you're not trusting that blindly, since it could be forged. It's better to keep a whitelist of IPs for which you trust it.

Other example:

String strHostName = new String("");
                        // Getting Ip address of local machine...
                        // First get the host name of local machine.
                        strHostName = DNS.GetHostName();

                        // Then using host name, get the IP address list..
                        IPHostEntry ipEntry = DNS.GetHostByName(strHostName);
                        IPAddress[] addr = ipEntry.AddressList;

Edited by Mitja Bonca: n/a

0

or:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
partial class how_to_Get_client_IP_address : System.Web.UI.Page
{

	protected void Page_Load(object sender, System.EventArgs e)
	{
		string ClientIP = null;
		ClientIP = Request.UserHostAddress;

		Label1.Text = ClientIP;
	}
	public how_to_Get_client_IP_address()
	{
		Load += Page_Load;
	}
}
0

But my question is how can i locate a city with respect to the Ip address , as in US so many cities will have same latitude and longitude values (or with slight variation in lat and long values)?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.