I have coded to find the ip addresses of my network. Now i need to code for finding the city,state,coun try, 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?
How to find the city,state,country, latitude, longitude of the user using java
Collapse
X
-
Tags: None
-
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 192.168.0.0 and 192.168.255.255 . 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 (ActiveDirector y) to find all data related to this DNS-name.
lookup DNS-name:
Code:InetAddress addr = InetAddress.getByName("192.168.178.1"); String host = addr.getHostName();
Code:import javax.naming.directory.*; Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); String url = "ldap://DNS_NAME_OR_IP_ADDRESS_OF_COMPANY_LDAP_SERVER"; env.put(Context.PROVIDER_URL, url); DirContext context = new InitialDirContext(env); ... // now lookup entries of interest, like city etc. ...
Comment