473,466 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

126 New Member
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
1 3305
chaarmann
785 Recognized Expert Contributor
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 (ActiveDirectory) to find all data related to this DNS-name.

lookup DNS-name:
Expand|Select|Wrap|Line Numbers
  1. InetAddress addr = InetAddress.getByName("192.168.178.1");
  2. String host = addr.getHostName();
  3.  
lookup LDAP (get directory):
Expand|Select|Wrap|Line Numbers
  1. import javax.naming.directory.*;
  2. Hashtable env = new Hashtable();
  3. env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
  4. String url = "ldap://DNS_NAME_OR_IP_ADDRESS_OF_COMPANY_LDAP_SERVER";
  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

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

Similar topics

1
by: B. G. Mahesh | last post by:
hi In the registration form I have city, state, country fields. I was wondering if there was a database available on the net which has the list of states in each of the countries. That way when...
2
by: serena | last post by:
hi i am working on a project in asp.net which has a page with details about a user. on filling the city or the country i want to know the time in that city or country and display in a label. ...
0
by: Poornima | last post by:
e.g:- if enetsl/Bsimth is the NT logi then how to do u get Bob Smith
1
by: greg.scharlemann | last post by:
Does anyone know where I could find a complete city and state database for MySQL? I've looked at the Zip Code data on the census website, but don't know the best approach to get a .dbf file into...
2
by: kbperry | last post by:
I am not sure if this is the right place for this, but I thought it was worth a shot. What I want: Enter a From: street address and a To: street address, and then specify an interval (say...
6
by: helpneeded | last post by:
Hi I am a novice using the <maptag. I have a question. I would really appreciate if you could answer me. I want to use the <maptag to dynamically update my map with coordinates. These...
6
by: gauravkhanna | last post by:
import java.io.*; class Automation1 implements Runnable { int iterationCount=0; Thread t; FileReader fr; //FileWriter fw; BufferedReader br; ...
13
by: anuradha135 | last post by:
I have a textarea in my jsp, where in the user will enter a sql query of select or insert or update or delete.I have to validate that entered data and say whether the query is syntatically correct...
4
by: cliffcoder2 | last post by:
hi, i m pappu jaiswal,i want to display city and country where our site will open so plz provide me appropriate code for this. thanks
0
by: SwapnilD | last post by:
I'm passing Multiple Lat/lan parameters to GOOGLE map to generate a MAP and also showing markers for all the locations based upon Lat/Lng. on mouseover event of Marker I'm showing pop up with some...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.