By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,804 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,804 IT Pros & Developers. It's quick & easy.

How to find the city,state,country, latitude, longitude of the user using java

P: 126
I have coded to find the ip addresses of my network. Now i need to code for finding the city,state,country, latitude, longitude with reference to the IP address, How do i do it? Is there any library or algorithms to do this using core java?
Jul 27 '13 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 785
What do you mean with "my network"? If you mean your home network, it does not make sense, because you know where you live. So it is your company network and it is a large company with computers in many countries. There, all IP-addresses of your computers will be given dynamically by the DNS-server and may change any time the computer is restarted, mostly in the range of and So you need to query the DNS-server to look up the DNS-name of the IP-Address. Then look up your company LDAP directory (ActiveDirectory) to find all data related to this DNS-name.

lookup DNS-name:
Expand|Select|Wrap|Line Numbers
  1. InetAddress addr = InetAddress.getByName("");
  2. String host = addr.getHostName();
lookup LDAP (get directory):
Expand|Select|Wrap|Line Numbers
  1. import*;
  2. Hashtable env = new Hashtable();
  3. env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  5.  env.put(Context.PROVIDER_URL, url);
  6. DirContext context = new InitialDirContext(env);
  7. ...
  8. // now lookup entries of interest, like city etc.
  9. ...
Jul 30 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.