I want to create a bash script to ping IP-adresses. It must first ask me the beginnen IP, then the ending IP like: 192.168.100.1 - 192.168.100.255.
When nothing is filled in, then it must find my subnet and ping that, like when my ip is 192.168.100.6, it must ping from 192.168.100.1 - 192.168.100.255.
Yes I do have a script where the IP is already filled in, but not one, which knows in which subnet you are, to ping all of the IP adresses there...
SYNOPSIS
netmask [ options ] spec [ spec ... ]
DESCRIPTION
This program accepts and produces a variety of common network address and netmask formats. Not only can it convert address and
netmask notations, but it will optimize the masks to generate the smallest list of rules. This is very handy if you've ever con
figured a firewall or router and some nasty network administrator before you decided that base 10 numbers were good places to
start and end groups of machines.
(...)
DEFINITIONS
A spec is an address specification, it can look like:
address One address.
address1:address2 All addresses from address1 to address2.
address1:+address2 All addresses from address1 to address1+address2.
address/mask A group starting at address spanning mask.
An address is an internet network address, it can look like:
ftp.gnu.org An internet hostname.
209.81.8.252 A standard dotted quad internet address notation.
100 A decimal number (100 in this case).
0100 An octal number preceded by "0" (64 in this case).
0x100 A hexadecimal number preceded by "0x" (256 in this case).
A mask is a network mask, it can look like:
255.255.224.0 A dotted quad netmask (netmask will complain if it is not a valid netmask).
0.0.31.255 A Cisco style inverse netmask (with the same checks).
8 The number of bits set to one from the left (CIDR notation).
010 The number of bits set to one from the left in octal.
0x10 The number of bits set to one from the left in hexadecimal.
AUTHOR
netmask was written by Robert Stone. Some algorithm design and optimization was provided by Tom Lear. This manual page was
written by Robert Stone.
It will show your IP. If my IP is something like 192.168.1.5, it has to ping every addres in the 192.168.1.* segment.
This script must also ping every address when I am also in a different segment like 192.1.1.*
How can I accomplish that?
---------- Post updated at 06:55 AM ---------- Previous update was at 06:18 AM ----------
The above will only grep the whole ip. I want to grep 192.168.1.
Only the first 3 adresses. The last one will be filled in by a sequence {1..255}
The question is how to grep the first 3 numbers. now it is 192.168.1 but on a different subnet it could be something like 10.1.1.*
You're assuming it's a 24-bit subnet. That's usually a good assumption with a local address like 192.168.x.x. But there's no reason it couldn't be a 16-bit or 26-bit or other size subnet (16-bit or larger for 192.168).
The Genmask column of the netstat -nr command output reveals the size of the netmask. A 24-bit subnet is shown as 255.255.255.0. A 27-bit subnet would be 255.255.255.224. Both are legitimate.
Many thanks for this one...
The above script is working! I can ping from beginning to ending IP-adresses very fast!
Lets go to the second part...
When no beginning and ending IP is given, so when the fields are empty.
The script must ping my own subnet!
This is the subnet where the system is logged in. So if I am in 192.168.100.* segmet it must ping from 192.168.100.1 to 192.168.100.255..
How can we accomplish this?
---------- Post updated at 08:35 AM ---------- Previous update was at 08:32 AM ----------
Or... the second part can be done like:
ping -b x.x.x.255
the tripple x must be filled in my the script by grepping my ip and pasting it there.