•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 422,560 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,694 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 2776 | Replies: 6 | Solved
![]() |
•
•
Join Date: Dec 2005
Posts: 45
Reputation:
Rep Power: 3
Solved Threads: 0
Hello, I was just wondering if it is possible in Java to get the host's IP address, as seen on the Internet, not network or by the computer itself. I mean, getting something like 87.253.145.35 instead of something like 192.168.1.100 or 127.0.0.1.
Or, if not, is there any popular/known server that has a static IP address with which I could open a Socket and have it tell me my IP address?
Or, if not, is there any popular/known server that has a static IP address with which I could open a Socket and have it tell me my IP address?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,114
Reputation:
Rep Power: 38
Solved Threads: 928
•
•
Join Date: Dec 2005
Posts: 45
Reputation:
Rep Power: 3
Solved Threads: 0
Ah, well, that won't really work in Java by itself, but, for those who care, this works (by utilizing a website like the one above):
If I could figure out what the index URL for whatismyip.org is (which has only 1 thing on it: the IP address), that would be even better. I've tried a lot of extensions to "index" and some to "default"....
try {
Socket sock = new Socket("www.edpsciences.org", 80);
BufferedReader is = new BufferedReader(new InputStreamReader(sock.getInputStream()));
PrintWriter os = new PrintWriter(sock.getOutputStream(), true);
// the actual URL is www.edpsciences.org/htbin/ipaddress (a ruby page)
os.println("GET /htbin/ipaddress HTTP/1.0");
os.println(); // two new lines are required to send a command
// the page has x number of lines with unnecessary information before it says "Your IP address"....
String line = "";
while(line.indexOf("Your IP address") == -1)
{
line = is.readLine();
}
// do a little substringing, and we'll have our answer (the ip address is inbetween "<B> " and " </B>"
String ipAddr = line.substring(line.indexOf("<B> ")+4, line.indexOf("</B>")-1);
}
catch (Exception e)
{
e.printStackTrace();
}If I could figure out what the index URL for whatismyip.org is (which has only 1 thing on it: the IP address), that would be even better. I've tried a lot of extensions to "index" and some to "default"....
•
•
Join Date: Jun 2004
Posts: 604
Reputation:
Rep Power: 6
Solved Threads: 6
Hi everyone,
Try looking at the java's InetAddress api, there maybe something useful there for you
http://java.sun.com/j2se/1.5.0/docs/...etAddress.html
Richard West
Try looking at the java's InetAddress api, there maybe something useful there for you
http://java.sun.com/j2se/1.5.0/docs/...etAddress.html
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Jun 2004
Posts: 604
Reputation:
Rep Power: 6
Solved Threads: 6
Hi everyone,
see the below threads
http://forum.java.sun.com/thread.jsp...62802&tstart=0
http://forum.java.sun.com/thread.jsp...hreadID=592585
http://forum.java.sun.com/thread.jsp...hreadID=520999
http://forum.java.sun.com/thread.jsp...hreadID=639572
http://sharkysoft.com/tutorials/jsa/content/040.html
http://forum.java.sun.com/thread.jsp...hreadID=143409
http://www.java-tips.org/java-se-tip...an-applet.html
http://forum.java.sun.com/thread.jsp...hreadID=218845
http://forum.java.sun.com/thread.jsp...hreadID=269203
Richard West
see the below threads
http://forum.java.sun.com/thread.jsp...62802&tstart=0
http://forum.java.sun.com/thread.jsp...hreadID=592585
http://forum.java.sun.com/thread.jsp...hreadID=520999
http://forum.java.sun.com/thread.jsp...hreadID=639572
http://sharkysoft.com/tutorials/jsa/content/040.html
http://forum.java.sun.com/thread.jsp...hreadID=143409
http://www.java-tips.org/java-se-tip...an-applet.html
http://forum.java.sun.com/thread.jsp...hreadID=218845
http://forum.java.sun.com/thread.jsp...hreadID=269203
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Dec 2005
Posts: 45
Reputation:
Rep Power: 3
Solved Threads: 0
All of those do not give the public IP address, except the fourth one (http://forum.java.sun.com/thread.jsp...hreadID=639572). However, the way suggested is just what I had thought of and implemented above.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- help in C, Find local Ip address (C)
- Get local IP address (VB.NET)
- creating a host name (Networking Hardware Configuration)
Other Threads in the Java Forum
- Previous Thread: Database error cord identify
- Next Thread: gif problem



Linear Mode