ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a way to easily discover active hosts on a subnet and parse their IPs into a file? I'm thinking about a bash script which follows the following psuedo code:
Code:
Obtain system IP through ifconfig and parsing out the IP using sed
Ping sweep subnet using nmap
Parse through output, looking for IP addresses returned
Add IPs to an array or CSV file
I'm just now learning about regex and I'm having trouble parsing the IP addresses. Is there an easy way to do this? Is there some much more obvious way of discovering active IPs that I'm just not thinking of?
Large problems are made easier by breaking them into smaller problems.
Quote:
Ping sweep subnet using nmap
Read the manpages for nmap(1). Search for ping sweep / ping scan.
Quote:
Parse through output, looking for IP addresses returned
Actually look at the output from nmap. You can't parse anything until you understand the data and its format.
Also, there are many ways to use regular expressions to match an IP address (some are more precise than others). I'd start by searching the forums and google.
Well, nmap is part of it, but it returns something like this:
Code:
[root@redshirt ~]# nmap -sP 192.168.1.0/24
Starting Nmap 4.53 ( http://insecure.org ) at 2008-07-22 22:49 CDT
Host boxA (192.168.1.100) appears to be up.
MAC Address: 00:11:22:33:44:55 (Cisco-Linksys)
Host boxB (192.168.1.105) appears to be up.
MAC Address: 00:21:12:34:43:01 (Tivo)
etc.
.
.
My question is on how to yank those IP addresses out of there so I can put them into an array or CSV.
Returns nothing. I realize though that by using grep, I would be returned the lines that contain the IPs rather than just the IPs. Is there a way to get just the IPs?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.