[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Scan a network to see if an IP address exists

Posted on 2005-04-06
18
Medium Priority
?
223 Views
Last Modified: 2010-03-31
Is there a way to validate an IP address, say with Socket without providing a port?  If not, is there another approach I could use to validate an IP address without using ping or tracert or making any kind of a call to the OS?  Thanks
0
Comment
Question by:jhughes4
  • 6
  • 4
  • 3
  • +3
18 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13720102
No, AFAIK
0
 

Author Comment

by:jhughes4
ID: 13720639
No for both I take it?
0
 
LVL 3

Expert Comment

by:Mig-O
ID: 13720670
Not without Invokation of Native Code.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:aozarov
ID: 13720681
Can't you assuem existence of starndard UDP ports (like ECHO/UDP, domain, ...).
If so, you can use DatagramSocket#connect(InetAddress address, int port) method.
0
 
LVL 3

Expert Comment

by:Mig-O
ID: 13720685
By the way... what is "validating" an IP Adress? Every response from an Computer in the world needs the "os" invoked, even to answer a simple ping.
0
 
LVL 3

Expert Comment

by:Mig-O
ID: 13720702
I'd adwise you to call "nmap" with stealth options from within java for the best results.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13720708
>> No for both I take it?

I meant for both, yes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13720768
Why, btw, do you not want to provide a port? If you're unsure of what services are running, you can simply try to connect to well-known ports
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13720786
0
 
LVL 3

Expert Comment

by:Mig-O
ID: 13720809
Hey, CEHJ, I think so... is there another reason to know for, if a machine is up? If it doesn't expose any services, it is useless for me anyway.
0
 

Author Comment

by:jhughes4
ID: 13721098
I was looking more for discovering a range of IP addresses provided by someone.  For example 192.168.1.100 to 192.168.1.120.  After receiving that range of IP addresses I wanted to go through the list to see which IP addresses were real and which were not assigned or not in use by a server.  After I obtain a list of those valid IP addresses on the network, there are some additional tasks that I would execute.

To answer you latest question CEHJ, ports are sometimes locked down by the network admins such as 25 for one reason or another, and I didn't want to rely on a port being locked down as an indication that the IP address wasn't being used by a server.

Mig-0 I've even seen ping locked down by the network.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 600 total points
ID: 13721167
>> I was looking more for discovering a range of IP addresses provided by someone.

In that case

http://java.sun.com/j2se/1.5.0/docs/api/java/net/InetAddress.html#getAllByName(java.lang.String)

may be more appropriate
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13721486
Can't you just ask the admin to allow the use of a specific port - for what you're doing?
Or, perhaps, just create an array of all of the most commonly open ports, then do for each IP address within the range, try and connect to it on each port, one-by-one; or if you can be bothered, multi-thread it, so that you can test several IPs at once..

Just a though..?

Regards;
0
 

Author Comment

by:jhughes4
ID: 13722408
CEHJ, I'm trying first getAllByName.  However, when I run the snippet of code below I get the same result if I enter a valid IP address or an invalid one.  The return is always whatever has been passed in ip_Address for instance "/192.168.1.110".  Is there something I'm doing wrong?

Thanks


String ip_Address = "192.168.1.110";


InetAddress[] address = InetAddress.getAllByName(ip_Address);

for (int i=0; i<address.length; i++) {
     System.out.println(address[i]);
}
0
 
LVL 15

Accepted Solution

by:
aozarov earned 600 total points
ID: 13722541
InetAddress doesn't say anything if you provided IP address (which is valid in its format) that can not be found in DNS lookup.
Basically reverse DNS lookup is done when you call getHostName on the ip address.
If reverse DNS lookup was seccessful the method will return the hostname otherwise it will return the same input.

e.g:
bsh % InetAddress.getByAddress(new byte[]{172,17,1,117}).getHostName();
<xxxx.yyyy.zzz.com>
or
bsh % InetAddress.getByName("172.17.1.117").getHostName();
<xxxx.yyyy.zzz.com>

Failed revers DNS lookup:
bsh % InetAddress.getByName("172.19.1.10").getHostName();
<172.19.1.10>


0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13724348
Just hitting an idea out of the box. If you really want to find out if an IP-address is valid (and up and running) without specifying a port, you can probably try pinging that machine using Runtime.exec () and read the response from it using:

http://www.javaalmanac.com/egs/java.lang/ReadFromCommand.html

You can also try: http://www.objects.com.au/java/examples/util/ConsoleExec.do

- then, parse that response and see what you got.
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 13726446
> without specifying a port, you can probably try pinging that machine using Runtime.exec ()
This wouldn't work -- because PING.exe basically creates a connection to the IP address, on the ICMP port.. So this connection will still be detected (and perhaps blocked).. you can perform an ICMP Echo Request (Ping) by simply creating a Socket conn to the IP on the ICMP port; as I've said though, it's still using a specific port.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13736282
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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