• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1469
  • Last Modified:

how to get ip address location in asp.net c# .net

hi,

I have returned an host ip address from:

so I wanna detect the location of that ip address, such as USA, NY, New York City

how can I do that in asp.net?
0
njgroup
Asked:
njgroup
  • 4
  • 2
  • 2
  • +1
3 Solutions
 
rdmustangCommented:
You can purchase 3rd party databases for IP address but they do change.

You might also script a lookup against a website that provides this information such as http://www.ip2location.com/free.asp

If you use a website then please check with the owner to make sure it's ok for you to query against it.
0
 
ProculopsisCommented:

Subscribe to a service like:

<form action="http://www.ipaddresslocation.org/ip-address-locator.php" method="POST">      	
                
<input type="text" name="ip" value="132.163.4.22" size="30" maxlength="16"> 

<input  type="submit" value="IP Locator" />

</form>

Open in new window

0
 
njgroupAuthor Commented:
thanks,

I wanna get the result in page load method instead of posting a form, isn't there any way to get a result in page load method?

    protected void Page_Load(object sender, EventArgs e)
    {
       // code to get location of remote host ip
    }
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
njgroupAuthor Commented:
thanks, but that doesn't help,

that works for get method, but not post!

how will I specify the IP address in post method?
0
 
njgroupAuthor Commented:
I mean that returns whole page!
in post method, how to specify parameter and get string of location only?
0
 
kovilpattiBaluCommented:
hi,
 protected void chkIPAddress_Click(object sender, EventArgs e)
        {
            string hostName = Dns.GetHostName();            
            Console.WriteLine("Host Name = " + hostName);
            IPHostEntry local = Dns.GetHostByName(hostName);
            foreach (IPAddress ipaddress in local.AddressList)
            {
                Console.WriteLine("IPAddress = " + ipaddress.ToString());
                result = result + ipaddress.ToString();
            }
            txtBrowser.Text = result ;
        }

http://www.codeproject.com/KB/IP/obafindingipinformation.aspx
0
 
kovilpattiBaluCommented:
0
 
njgroupAuthor Commented:
that's great, but do u have a db for cities free?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now