Solved

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

Posted on 2010-11-17
9
1,377 Views
Last Modified: 2013-12-17
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
Comment
Question by:njgroup
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 3

Assisted Solution

by:rdmustang
rdmustang earned 75 total points
ID: 34157455
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
 
LVL 20

Assisted Solution

by:Proculopsis
Proculopsis earned 75 total points
ID: 34157506

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
 

Author Comment

by:njgroup
ID: 34157725
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 3

Expert Comment

by:rdmustang
ID: 34158599
0
 

Author Comment

by:njgroup
ID: 34162247
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
 

Author Comment

by:njgroup
ID: 34162264
I mean that returns whole page!
in post method, how to specify parameter and get string of location only?
0
 
LVL 7

Expert Comment

by:kovilpattiBalu
ID: 34162552
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
 
LVL 7

Accepted Solution

by:
kovilpattiBalu earned 350 total points
ID: 34162575
0
 

Author Closing Comment

by:njgroup
ID: 34180143
that's great, but do u have a db for cities free?
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question