Link to home
Start Free TrialLog in
Avatar of jhughes4
jhughes4

asked on

Scan a network to see if an IP address exists

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

No, AFAIK
Avatar of jhughes4
jhughes4

ASKER

No for both I take it?
Not without Invokation of Native Code.
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.
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.
I'd adwise you to call "nmap" with stealth options from within java for the best results.
>> No for both I take it?

I meant for both, yes
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
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.
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.
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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;
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]);
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
> 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.
:-)