Solved

Finding machines in a particular subnet

Posted on 2000-04-12
2
205 Views
Last Modified: 2013-12-06
I have a machine whose IP is a.b.c.d and wish to locate all other machines whose IP starts with a.b
Is there a command, either on NT or UNIX, that will do this for me recursively?
0
Comment
Question by:rsorrent
2 Comments
 
LVL 20

Expert Comment

by:tfewster
ID: 2709868
You might be able to do it with snoop/tcpdump, but the following scripts should also do the job.

Build a list of valid addresses, excluding 0, 254 & 255 ("specials")

possible.sh:
#!/usr/bin/ksh
i=1
j=1
while [ $i -lt 254 ]
do
  while [ $j -lt 254 ]
  do
    echo "a.b."$i"."$j >> /tmp/possible
    i=$(($i+1))
  done
  i=$(($i+1))
done

Now try to ping the possibles:
response.sh:
#!/usr/bin/ksh
for ADDRESS in `cat /tmp/possible`
do
  RESPONSE=""
  RESPONSE=`ping $ADDRESS | grep Reply`
  # NB, ping is OS dependent, e.g. in
  # HP-UX you must add the option
  # "-c count", or it will retry the
  # ping indefinitely
  if [ ! X$RESPONSE = X ] ; then
     echo $ADDRESS >> /tmp/responses
  else
     echo $ADDRESS >> /tmp/noresponse
  fi
done

/tmp/responses will then be a list of all devices that are alive & have an IP address in that range, including Unix boxes, PCs, print servers etc. I guess the next step is to try to classify them...

/tmp/noresponse would be possible free IP addresses - assuming the device isn't switched off :(
0
 

Accepted Solution

by:
sgoldgaber earned 200 total points
ID: 2710392
NMAP is a tool that can do what you want and much much much more:

http://www.insecure.org/nmap/index.html
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

810 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