while do read done in one line

This is a simple but useful loop to process an input file if none can be provide with a command option for a certain program. E.g. use every IP address in a file
To be used in bash when you don’t want to write a script just yet.

guru@home:~/utils$ while read -r LINE; do echo "$LINE";sleep 1; done < targethosts.txt
172.16.1.254
172.16.3.11
172.16.3.41
172.16.3.51
172.16.3.61
172.16.3.71
172.16.3.111
172.16.3.253
172.16.4.74
172.16.4.79
172.16.4.80
172.16.4.155
172.16.4.254
172.16.4.76
172.16.4.76
172.16.4.91

Instead of an ordinary echo you would of course use another command.

E.g. a simple ping to each host

guru@home:~/utils$ while read -r LINE; do ping -c2 "$LINE"; done < targethosts.txt
PING 172.16.1.254 (172.16.1.254) 56(84) bytes of data.
64 bytes from 172.16.1.254: icmp_seq=1 ttl=64 time=0.612 ms
64 bytes from 172.16.1.254: icmp_seq=2 ttl=64 time=0.516 ms

--- 172.16.1.254 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1009ms
rtt min/avg/max/mdev = 0.516/0.564/0.612/0.048 ms
PING 172.16.3.11 (172.16.3.11) 56(84) bytes of data.
64 bytes from 172.16.3.11: icmp_seq=1 ttl=127 time=1.50 ms
64 bytes from 172.16.3.11: icmp_seq=2 ttl=127 time=1.39 ms

--- 172.16.3.11 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.392/1.446/1.501/0.066 ms
PING 172.16.3.41 (172.16.3.41) 56(84) bytes of data.
64 bytes from 172.16.3.41: icmp_seq=1 ttl=127 time=1.06 ms
64 bytes from 172.16.3.41: icmp_seq=2 ttl=127 time=1.23 ms


LSOF commands

lsof
====
lsof – list open files

guru@home:~$ sudo lsof -h
lsof 4.89
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
 [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
  -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)    +d s  dir s files
  -d s  select by FD set   +D D  dir D tree *SLOW?*   +|-e s  exempt s *RISKY*
  -i select IPv[46] files  -K list tasKs (threads)    -l list UID numbers
  -n no host names         -N select NFS files        -o list file offset
  -O no overhead *RISKY*   -P no port names           -R list paRent PID
  -s list file size        -t terse listing           -T disable TCP/TPI info
  -U select Unix socket    -v list version info       -V verbose search
  +|-w  Warnings (+)       -X skip TCP&UDP* files     -Z Z  context [Z]
  -- end option scan     
  -E display endpoint info              +E display endpoint info and files
  +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
  -F [f] select fields; -F? for help  
  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                        +m [m] use|create mount supplement
  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
  -T qs TCP/TPI Q,St (s) info
  -g [s] exclude(^)|select and print process group IDs
  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
  +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, - forever.
       An optional suffix to t is m<fmt>; m must separate t from <fmt> and
      <fmt> is an strftime(3) format for the marker line.
  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).
  -u s   exclude(^)|select login|UID set s
  -x [fl] cross over +d|+D File systems or symbolic Links
  names  select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.

all files you have opened as logged on user

guru@home:~$ lsof -u `whoami` | wc -l
3316

files opened in a directory
—————————

guru@home:~$ sudo lsof +D /etc/
COMMAND     PID  USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
avahi-dae   531 avahi  cwd    DIR    8,1     4096 46138635 /etc/avahi
avahi-dae   531 avahi  rtd    DIR    8,1     4096 46138635 /etc/avahi
sh        10201  guru   10r   REG    8,1     5873 46138915 /etc/xdg/xfce4/xinitrc

files opened by bash
——————–

guru@home:~$ sudo lsof -c bash
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
bash     5750 guru  cwd    DIR    8,1     4096  3670018 /home/guru
bash     5750 guru  rtd    DIR    8,1     4096        2 /
bash     5750 guru  txt    REG    8,1  1099016 34340977 /bin/bash
bash     5750 guru  mem    REG    8,1    47632 49286244 /lib/x86_64-linux-gnu/libnss_files-2.24.so
bash     5750 guru  mem    REG    8,1    47688 49286246 /lib/x86_64-linux-gnu/libnss_nis-2.24.so
.
.
bash    16945 guru  mem    REG    8,1   170776 49283165 /lib/x86_64-linux-gnu/libtinfo.so.5.9
bash    16945 guru  mem    REG    8,1   153288 49286230 /lib/x86_64-linux-gnu/ld-2.24.so
bash    16945 guru  mem    REG    8,1  1683008 11797031 /usr/lib/locale/locale-archive
bash    16945 guru  mem    REG    8,1    26258 11802677 /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
bash    16945 guru  255u   CHR  136,1      0t0        4 /dev/pts/1
guru@home:~$ sudo lsof -c dhcli
COMMAND    PID USER   FD   TYPE             DEVICE SIZE/OFF     NODE NAME
dhclient 13920 root  cwd    DIR                8,1     4096        2 /
dhclient 13920 root  rtd    DIR                8,1     4096        2 /
dhclient 13920 root  txt    REG                8,1   487728 39059510 /sbin/dhclient
dhclient 13920 root  mem    REG                8,1    47632 49286244 /lib/x86_64-linux-gnu/libnss_files-2.24.so
dhclient 13920 root  mem    REG                8,1  2492192 11801803 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2
.
.
dhclient 15121 root    2w   CHR                1,3      0t0     1028 /dev/null
dhclient 15121 root    3u  unix 0xffff95d879fcc800      0t0   186960 type=DGRAM
dhclient 15121 root    4w   REG                8,1     7696 53477431 /var/lib/NetworkManager/dhclient-365be78a-08f5-4443-b128-be2e48fb8b36-enp0s25.lease
dhclient 15121 root    5u  pack             194950      0t0      ALL type=SOCK_RAW
dhclient 15121 root    6u  IPv4             194952      0t0      UDP *:bootpc 
guru@home:~$ sudo lsof -c net
COMMAND PID USER   FD      TYPE DEVICE SIZE/OFF NODE NAME
netns    56 root  cwd       DIR    8,1     4096    2 /
netns    56 root  rtd       DIR    8,1     4096    2 /
netns    56 root  txt   unknown                      /proc/56/exe
guru@home:~$ sudo lsof -c ssh
COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF     NODE NAME
ssh-agent 10238 guru  cwd    DIR                8,1     4096        2 /
ssh-agent 10238 guru  rtd    DIR                8,1     4096        2 /
ssh-agent 10238 guru  txt    REG                8,1   358624 11807359 /usr/bin/ssh-agent
ssh-agent 10238 guru  mem    REG                8,1    14640 49286237 /lib/x86_64-linux-gnu/libdl-2.24.so
ssh-agent 10238 guru  mem    REG                8,1  1685264 49286234 /lib/x86_64-linux-gnu/libc-2.24.so
ssh-agent 10238 guru  mem    REG                8,1  2492192 11801803 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2
ssh-agent 10238 guru  mem    REG                8,1   153288 49286230 /lib/x86_64-linux-gnu/ld-2.24.so
ssh-agent 10238 guru    0u   CHR                1,3      0t0     1028 /dev/null
ssh-agent 10238 guru    1u   CHR                1,3      0t0     1028 /dev/null
ssh-agent 10238 guru    2u   CHR                1,3      0t0     1028 /dev/null
ssh-agent 10238 guru    3u  unix 0xffff95d851968c00      0t0   126742 /tmp/ssh-Ar27ChhjIh2b/agent.10201 type=STREAM

files opened by a process
eg the pid of firefox

guru@home:~$ sudo lsof -p 16116
COMMAND     PID USER   FD      TYPE             DEVICE SIZE/OFF     NODE NAME
plugin-co 16116 guru  cwd       DIR                8,1     4096  3670018 /home/guru
plugin-co 16116 guru  rtd       DIR                8,1     4096        2 /
plugin-co 16116 guru  txt       REG                8,1   261944 12846344 /usr/lib/firefox-esr/plugin-container
plugin-co 16116 guru  DEL       REG                0,5          43974662 /SYSV00000000
plugin-co 16116 guru  mem       REG                8,1    14232 11806677 /usr/lib/x86_64-linux-gnu/libvdpau.so.1.0.0
.
.
plugin-co 16116 guru   14w     FIFO               0,10      0t0   210188 pipe
plugin-co 16116 guru   15u     unix 0xffff95d874c26800      0t0   204431 type=STREAM
plugin-co 16116 guru   16r      REG                8,1   327680  3670105 /home/guru/.mozilla/firefox/xjyhxitc.default/cert8.db
plugin-co 16116 guru   17r      REG                8,1    16384  3670106 /home/guru/.mozilla/firefox/xjyhxitc.default/key3.db
plugin-co 16116 guru   18u  a_inode               0,11        0     9538 [eventfd]
plugin-co 16116 guru   19u  a_inode               0,11        0     9538 [eventfd]

lsof for networking
——————-
-i select IPv[46] files

guru@home:~$ sudo lsof -i
COMMAND     PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
avahi-dae   531 avahi   12u  IPv4    680      0t0  UDP *:mdns 
avahi-dae   531 avahi   13u  IPv6    681      0t0  UDP *:mdns 
avahi-dae   531 avahi   14u  IPv4    682      0t0  UDP *:47279 
avahi-dae   531 avahi   15u  IPv6    683      0t0  UDP *:57118 
firefox-e 10356  guru   81u  IPv4 268390      0t0  TCP 172.16.4.91:40490->ams15s22-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356  guru   83u  IPv4 267435      0t0  TCP 172.16.4.91:33536->ams16s29-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356  guru   98u  IPv4 264911      0t0  TCP 172.16.4.91:58772->ec2-54-225-163-44.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356  guru  129u  IPv4 230447      0t0  TCP 172.16.4.91:55832->ec2-54-224-188-111.compute-1.amazonaws.com:https (ESTABLISHED)
dhclient  13920  root    6u  IPv4 182622      0t0  UDP *:bootpc 
dhclient  14233  root    6u  IPv4 178049      0t0  UDP *:bootpc 
dhclient  14318  root    6u  IPv4 176042      0t0  UDP *:bootpc 
dhclient  14596  root    6u  IPv4 191123      0t0  UDP *:bootpc 
dhclient  15121  root    6u  IPv4 194952      0t0  UDP *:bootpc 
cupsd     15538  root    9u  IPv6 199931      0t0  TCP localhost:ipp (LISTEN)
cupsd     15538  root   10u  IPv4 199932      0t0  TCP localhost:ipp (LISTEN)
cups-brow 15539  root    7u  IPv4 198756      0t0  UDP *:ipp

-s p:s exclude(^)|select protocol (p = TCP|UDP) states by name(s).

guru@home:~$ sudo lsof -i -s tcp:listen
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
cupsd   15538 root    9u  IPv6 199931      0t0  TCP localhost:ipp (LISTEN)
cupsd   15538 root   10u  IPv4 199932      0t0  TCP localhost:ipp (LISTEN)
guru@home:~$ sudo lsof -i -s tcp:established
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   81u  IPv4 270686      0t0  TCP 172.16.4.91:47818->ec2-54-175-254-119.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 264911      0t0  TCP 172.16.4.91:58772->ec2-54-225-163-44.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356 guru  129u  IPv4 230447      0t0  TCP 172.16.4.91:55832->ec2-54-224-188-111.compute-1.amazonaws.com:https (ESTABLISHED)
guru@home:~$ sudo lsof -i 6 -s tcp:listen
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
cupsd   15538 root    9u  IPv6 199931      0t0  TCP localhost:ipp (LISTEN)
guru@home:~$ sudo lsof -i 4 -s tcp:established
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   81u  IPv4 270710      0t0  TCP 172.16.4.91:56422->ec2-34-206-132-93.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 267622      0t0  TCP 172.16.4.91:39070->ams16s22-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 264911      0t0  TCP 172.16.4.91:58772->ec2-54-225-163-44.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356 guru  129u  IPv4 230447      0t0  TCP 172.16.4.91:55832->ec2-54-224-188-111.compute-1.amazonaws.com:https (ESTABLISHED)

source ip
———-

guru@home:~$ sudo lsof -i@172.16.4.91
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   85u  IPv4 267622      0t0  TCP 172.16.4.91:39070->ams16s22-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 264911      0t0  TCP 172.16.4.91:58772->ec2-54-225-163-44.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356 guru  129u  IPv4 230447      0t0  TCP 172.16.4.91:55832->ec2-54-224-188-111.compute-1.amazonaws.com:https (ESTABLISHED)

exclude user
————

guru@home:~$ lsof -u ^guru

By default when you use more than one list option in lsof, they will be ORed.
——————————————————————————
-a AND selections

guru@home:~$ sudo lsof -i@172.16.4.91 -u guru -a
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   81u  IPv4 274022      0t0  TCP 172.16.4.91:41908->ec2-23-21-83-14.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 279138      0t0  TCP 172.16.4.91:52108->ec2-52-55-162-68.compute-1.amazonaws.com:http (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 267993      0t0  TCP 172.16.4.91:45896->ams16s31-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 279037      0t0  TCP 172.16.4.91:49284->ams15s29-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 279112      0t0  TCP 172.16.4.91:33448->ams16s30-in-f66.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru   99u  IPv4 279110      0t0  TCP 172.16.4.91:41516->ams16s31-in-f2.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  106u  IPv4 273999      0t0  TCP 172.16.4.91:38956->edge-star-mini-shv-01-iad3.facebook.com:https (ESTABLISHED)
firefox-e 10356 guru  108u  IPv4 274000      0t0  TCP 172.16.4.91:45926->ams16s31-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  111u  IPv4 279018      0t0  TCP 172.16.4.91:53064->ams15s30-in-f142.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  113u  IPv4 279009      0t0  TCP 172.16.4.91:51764->ams15s30-in-f132.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 279034      0t0  TCP 172.16.4.91:39706->ams15s30-in-f134.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  115u  IPv4 274911      0t0  TCP 172.16.4.91:45932->ams16s31-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  116u  IPv4 268115      0t0  TCP 172.16.4.91:45928->ams16s31-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  118u  IPv4 279061      0t0  TCP 172.16.4.91:43220->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  119u  IPv4 274003      0t0  TCP 172.16.4.91:48542->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  120u  IPv4 279047      0t0  TCP 172.16.4.91:34208->xx-fbcdn-shv-01-bru2.fbcdn.net:https (ESTABLISHED)
firefox-e 10356 guru  122u  IPv4 274914      0t0  TCP 172.16.4.91:43932->ams15s30-in-f13.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  125u  IPv4 274924      0t0  TCP 172.16.4.91:42470->199.16.156.52:https (ESTABLISHED)
firefox-e 10356 guru  127u  IPv4 279048      0t0  TCP 172.16.4.91:43174->104.19.194.102:https (ESTABLISHED)
firefox-e 10356 guru  133u  IPv4 274006      0t0  TCP 172.16.4.91:44406->ams15s30-in-f138.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  140u  IPv4 271141      0t0  TCP 172.16.4.91:39644->ams15s30-in-f134.1e100.net:https (ESTABLISHED)
guru@home:~$ sudo lsof -i -a -c firefox-e
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   83u  IPv4 276074      0t0  TCP 172.16.4.91:53602->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 281738      0t0  TCP 172.16.4.91:34222->ams16s29-in-f46.1e100.net:https (ESTABLISHED)

List process IDs for processes being run by a particular user.
————————————————————–

guru@home:~$ sudo lsof -t -u guru
769
770
786
827
832
840
844
856
864
888
917
919
946
960
5750
10201
10238
10248
10250
10259
10260
10262
10263
10265
10273
10274
10277
10296
10299
10301
10307
10356
11227
11232
11437
11444
13128
13129
13310
14722
16116
16945

kill all files opened by a user
——————————-

-t terse listing

kill -9 `lsof -t -u guru`

Execute lsof in repeat mode
—————————-

It will first list files based on the given parameters and delay for specified seconds and again list files based on the given parameters
It can be interrupted by a signal.

Repeat mode can be enabled by using ‘-r’ or ‘+r’. If ‘+r’ is used then, the repeat mode will end when no open files are found.
‘-r’ will continue to list,delay,list until a interrupt is given irrespective of files are opened or not.

Each cycle output will be separated by using ‘=======’. You also also specify the time delay as ‘-r’ | ‘+r’.

guru@home:~$ lsof -i -a -s tcp:established -r 5
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   83u  IPv4 283891      0t0  TCP 172.16.4.91:56136->ams15s30-in-f133.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 284081      0t0  TCP 172.16.4.91:53672->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 284729      0t0  TCP 172.16.4.91:49134->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 283892      0t0  TCP 172.16.4.91:43736->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 284730      0t0  TCP 172.16.4.91:49136->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  101u  IPv4 284083      0t0  TCP 172.16.4.91:38886->104.28.18.50:https (ESTABLISHED)
firefox-e 10356 guru  103u  IPv4 284756      0t0  TCP 172.16.4.91:40598->ams15s30-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  105u  IPv4 287824      0t0  TCP 172.16.4.91:37206->ams15s30-in-f10.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 283915      0t0  TCP 172.16.4.91:53634->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  139u  IPv4 285809      0t0  TCP 172.16.4.91:47490->ef-in-f189.1e100.net:https (ESTABLISHED)
=======
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   81u  IPv4 282458      0t0  TCP 172.16.4.91:40788->mail.unipartners.org:http (ESTABLISHED)
firefox-e 10356 guru   83u  IPv4 283891      0t0  TCP 172.16.4.91:56136->ams15s30-in-f133.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 284081      0t0  TCP 172.16.4.91:53672->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 284729      0t0  TCP 172.16.4.91:49134->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 283892      0t0  TCP 172.16.4.91:43736->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 284730      0t0  TCP 172.16.4.91:49136->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  101u  IPv4 284083      0t0  TCP 172.16.4.91:38886->104.28.18.50:https (ESTABLISHED)
firefox-e 10356 guru  103u  IPv4 284756      0t0  TCP 172.16.4.91:40598->ams15s30-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  105u  IPv4 287824      0t0  TCP 172.16.4.91:37206->ams15s30-in-f10.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 283915      0t0  TCP 172.16.4.91:53634->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  139u  IPv4 285809      0t0  TCP 172.16.4.91:47490->ef-in-f189.1e100.net:https (ESTABLISHED)
=======
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   83u  IPv4 283891      0t0  TCP 172.16.4.91:56136->ams15s30-in-f133.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 284081      0t0  TCP 172.16.4.91:53672->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 284729      0t0  TCP 172.16.4.91:49134->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 283892      0t0  TCP 172.16.4.91:43736->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 284730      0t0  TCP 172.16.4.91:49136->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   99u  IPv4 284836      0t0  TCP 172.16.4.91:58028->wilder.debian.org:https (ESTABLISHED)
firefox-e 10356 guru  101u  IPv4 284083      0t0  TCP 172.16.4.91:38886->104.28.18.50:https (ESTABLISHED)
firefox-e 10356 guru  103u  IPv4 284756      0t0  TCP 172.16.4.91:40598->ams15s30-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  105u  IPv4 287824      0t0  TCP 172.16.4.91:37206->ams15s30-in-f10.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 283915      0t0  TCP 172.16.4.91:53634->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  139u  IPv4 285809      0t0  TCP 172.16.4.91:47490->ef-in-f189.1e100.net:https (ESTABLISHED)
=======
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   83u  IPv4 283891      0t0  TCP 172.16.4.91:56136->ams15s30-in-f133.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 284081      0t0  TCP 172.16.4.91:53672->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 284729      0t0  TCP 172.16.4.91:49134->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 283892      0t0  TCP 172.16.4.91:43736->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 284730      0t0  TCP 172.16.4.91:49136->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  101u  IPv4 284083      0t0  TCP 172.16.4.91:38886->104.28.18.50:https (ESTABLISHED)
firefox-e 10356 guru  103u  IPv4 284756      0t0  TCP 172.16.4.91:40598->ams15s30-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  105u  IPv4 287824      0t0  TCP 172.16.4.91:37206->ams15s30-in-f10.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 283915      0t0  TCP 172.16.4.91:53634->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  139u  IPv4 285809      0t0  TCP 172.16.4.91:47490->ef-in-f189.1e100.net:https (ESTABLISHED)
=======
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   83u  IPv4 283891      0t0  TCP 172.16.4.91:56136->ams15s30-in-f133.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 284081      0t0  TCP 172.16.4.91:53672->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 284729      0t0  TCP 172.16.4.91:49134->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 283892      0t0  TCP 172.16.4.91:43736->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 284730      0t0  TCP 172.16.4.91:49136->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   99u  IPv4 282464      0t0  TCP 172.16.4.91:58030->wilder.debian.org:https (ESTABLISHED)
firefox-e 10356 guru  101u  IPv4 284083      0t0  TCP 172.16.4.91:38886->104.28.18.50:https (ESTABLISHED)
firefox-e 10356 guru  103u  IPv4 284756      0t0  TCP 172.16.4.91:40598->ams15s30-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  105u  IPv4 287824      0t0  TCP 172.16.4.91:37206->ams15s30-in-f10.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 283915      0t0  TCP 172.16.4.91:53634->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  139u  IPv4 285809      0t0  TCP 172.16.4.91:47490->ef-in-f189.1e100.net:https (ESTABLISHED)
=======
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   83u  IPv4 283891      0t0  TCP 172.16.4.91:56136->ams15s30-in-f133.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 284081      0t0  TCP 172.16.4.91:53672->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 284729      0t0  TCP 172.16.4.91:49134->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 283892      0t0  TCP 172.16.4.91:43736->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 284730      0t0  TCP 172.16.4.91:49136->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  101u  IPv4 284083      0t0  TCP 172.16.4.91:38886->104.28.18.50:https (ESTABLISHED)
firefox-e 10356 guru  103u  IPv4 284756      0t0  TCP 172.16.4.91:40598->ams15s30-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  105u  IPv4 287824      0t0  TCP 172.16.4.91:37206->ams15s30-in-f10.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 283915      0t0  TCP 172.16.4.91:53634->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  139u  IPv4 285809      0t0  TCP 172.16.4.91:47490->ef-in-f189.1e100.net:https (ESTABLISHED)
=======
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
firefox-e 10356 guru   81u  IPv4 284099      0t0  TCP 172.16.4.91:36412->senfter.debian.org:https (ESTABLISHED)
firefox-e 10356 guru   83u  IPv4 283891      0t0  TCP 172.16.4.91:56136->ams15s30-in-f133.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   84u  IPv4 284081      0t0  TCP 172.16.4.91:53672->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   85u  IPv4 282469      0t0  TCP 172.16.4.91:36414->senfter.debian.org:https (ESTABLISHED)
firefox-e 10356 guru   88u  IPv4 283892      0t0  TCP 172.16.4.91:43736->ams15s30-in-f3.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   98u  IPv4 284730      0t0  TCP 172.16.4.91:49136->ams15s30-in-f1.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru   99u  IPv4 282470      0t0  TCP 172.16.4.91:36416->senfter.debian.org:https (ESTABLISHED)
firefox-e 10356 guru  101u  IPv4 284083      0t0  TCP 172.16.4.91:38886->104.28.18.50:https (ESTABLISHED)
firefox-e 10356 guru  103u  IPv4 284756      0t0  TCP 172.16.4.91:40598->ams15s30-in-f2.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  105u  IPv4 287824      0t0  TCP 172.16.4.91:37206->ams15s30-in-f10.1e100.net:http (ESTABLISHED)
firefox-e 10356 guru  106u  IPv4 282471      0t0  TCP 172.16.4.91:36418->senfter.debian.org:https (ESTABLISHED)
firefox-e 10356 guru  108u  IPv4 282472      0t0  TCP 172.16.4.91:36420->senfter.debian.org:https (ESTABLISHED)
firefox-e 10356 guru  110u  IPv4 282473      0t0  TCP 172.16.4.91:36422->senfter.debian.org:https (ESTABLISHED)
firefox-e 10356 guru  114u  IPv4 283915      0t0  TCP 172.16.4.91:53634->ams15s30-in-f14.1e100.net:https (ESTABLISHED)
firefox-e 10356 guru  139u  IPv4 285809      0t0  TCP 172.16.4.91:47490->ef-in-f189.1e100.net:https (ESTABLISHED)
=======
^C

cli tools to assist you in subnetting a network

If your into networking you should be able to do all subnetting without any tools but sometimes human error can creep up or you just want things done quickly

These are the command line interface tools I found helpful for subnetting:

  1. sipcalc
    
    guru@home:~$ sipcalc --help
    sipcalc 1.1.5
    
    Usage: sipcalc [OPTIONS]... <[ADDRESS]... [INTERFACE]... | [-]>
    
    Global options:
     -a, --all All possible information.
     -d, --resolve Enable name resolution.
     -h, --help Display this help.
     -I, --addr-int=INT Added an interface.
     -n, --subnets=NUM Display NUM extra subnets (starting from
     the current subnet). Will display all subnets
     in the current /24 if NUM is 0.
     -u, --split-verbose Verbose split.
     -v, --version Version information.
     -4, --addr-ipv4=ADDR Add an ipv4 address.
     -6, --addr-ipv6=ADDR Add an ipv6 address.
    
    IPv4 options:
     -b, --cidr-bitmap CIDR bitmap.
     -c, --classfull-addr Classfull address information.
     -i, --cidr-addr CIDR address information. (default)
     -s, --v4split=MASK Split the current network into subnets
     of MASK size.
     -w, --wildcard Display information for a wildcard
     (inverse mask).
     -x, --classfull-bitmap Classfull bitmap.
    
    IPv6 options:
     -e, --v4inv6 IPv4 compatible IPv6 information.
     -r, --v6rev IPv6 reverse DNS output.
     -S, --v6split=MASK Split the current network into subnets
     of MASK size.
     -t, --v6-standard Standard IPv6. (default)
    
    Address must be in the "standard" dotted quad format.
    Netmask can be given in three different ways:
     - Number of bits [/nn]
     - Dotted quad [nnn.nnn.nnn.nnn]
     - Hex [0xnnnnnnnn | nnnnnnnn]
    
    Interface must be a valid network interface on the system.
    If this options is used an attempt will be made to gain the address
    and netmask from the specified interface.
    
    Replacing address/interface with '-' will use stdin for reading further
    arguments.
    
    Report bugs to <simon@routemeister.net>.
    

    so for example you want to understand the Global Unicast Address range

    guru@home:~$ sipcalc -a -6 2000::/3
    -[ipv6 : 2000::/3] - 0
    
    [IPV6 INFO]
    Expanded Address	- 2000:0000:0000:0000:0000:0000:0000:0000
    Compressed address	- 2000::
    Subnet prefix (masked)	- 2000:0:0:0:0:0:0:0/3
    Address ID (masked)	- 0:0:0:0:0:0:0:0/3
    Prefix address		- e000:0:0:0:0:0:0:0
    Prefix length		- 3
    Address type		- Aggregatable Global Unicast Addresses
    Network range		- 2000:0000:0000:0000:0000:0000:0000:0000 -
    			  3fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
    
    [V4INV6]
    Expanded v4inv6 address	- 2000:0000:0000:0000:0000:0000:0.0.0.0
    Compr. v4inv6 address	- 2000::0.0.0.0
    
    [IPV6 DNS]
    Reverse DNS (ip6.arpa)	-
    0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.ip6.arpa.
    
    -
    
    

    Or say you want to know the range of the subnets for a given IP address and you want 4 including the one for which you provide the IP (you can leave the -a option)

    e.g. 10.6.14.4/20

    guru@home:~$ sipcalc -a -n4 10.5.14.4/20
    -[ipv4 : 10.5.14.4/20] - 0
    
    [Classfull]
    Host address		- 10.5.14.4
    Host address (decimal)	- 168103428
    Host address (hex)	- A050E04
    Network address		- 10.0.0.0
    Network class		- A
    Network mask		- 255.0.0.0
    Network mask (hex)	- FF000000
    Broadcast address	- 10.255.255.255
    
    [CIDR]
    Host address		- 10.5.14.4
    Host address (decimal)	- 168103428
    Host address (hex)	- A050E04
    Network address		- 10.5.0.0
    Network mask		- 255.255.240.0
    Network mask (bits)	- 20
    Network mask (hex)	- FFFFF000
    Broadcast address	- 10.5.15.255
    Cisco wildcard		- 0.0.15.255
    Addresses in network	- 4096
    Network range		- 10.5.0.0 - 10.5.15.255
    Usable range		- 10.5.0.1 - 10.5.15.254
    
    [Classfull bitmaps]
    Network address		- 00001010.00000000.00000000.00000000
    Network mask		- 11111111.00000000.00000000.00000000
    
    [CIDR bitmaps]
    Host address		- 00001010.00000101.00001110.00000100
    Network address		- 00001010.00000101.00000000.00000000
    Network mask		- 11111111.11111111.11110000.00000000
    Broadcast address	- 00001010.00000101.00001111.11111111
    Cisco wildcard		- 00000000.00000000.00001111.11111111
    Network range		- 00001010.00000101.00000000.00000000 -
    			  00001010.00000101.00001111.11111111
    Usable range		- 00001010.00000101.00000000.00000001 -
    			  00001010.00000101.00001111.11111110
    
    [Networks]
    Network			- 10.5.0.0        - 10.5.15.255 (current)
    Network			- 10.5.16.0       - 10.5.31.255
    Network			- 10.5.32.0       - 10.5.47.255
    Network			- 10.5.48.0       - 10.5.63.255
    
    
    
  2. bindechexascii
    (handy for teachers)

    guru@home:~$ bindechexascii --help
    
    Usage: bindechexascii [mode] arg1 arg2 arg3 ...
    
    Convert:
     --b2d     Binary to decimal
     --b2h     Binary to hexadecimal
     --b2a     Binary to ASCII
    
     --d2b     Decimal to binary
     --d2h     Decimal to hexadecimal
     --d2a     Decimal to ASCII
    
     --h2b     Hexadecimal to binary
     --h2d     Hexadecimal to decimal
     --h2a     Hexadecimal to ASCII
    
     --a2b     ASCII to binary
     --a2d     ASCII to decimal
     --a2h     ASCII to hexadecimal
    
     -h --help    Print this help
     -i --info    Print information about program
    
    guru@home:~$ bindechexascii --h2b 2001 FE80
    Hexadecimal to Binary: 0010000000000001 1111111010000000
    
    guru@home:~$ bindechexascii --d2h 192 168 4 66
    Decimal to Hexadecimal: C0 A8 4 42 
    
  3. subnetcalc

    Usage:
    subnetcalc [Address{/{Netmask|Prefix}}] {Netmask|Prefix} {-n} {-uniquelocal|-uniquelocalhq}

    guru@home:~$ subnetcalc 2001:fe80:ABCD:EF::/64
    Address       = 2001:fe80:abcd:ef::
                       2001 = 00100000 00000001
                       fe80 = 11111110 10000000
                       abcd = 10101011 11001101
                       00ef = 00000000 11101111
                       0000 = 00000000 00000000
                       0000 = 00000000 00000000
                       0000 = 00000000 00000000
                       0000 = 00000000 00000000
    Network       = 2001:fe80:abcd:ef:: / 64
    Netmask       = ffff:ffff:ffff:ffff::
    Wildcard Mask = ::ffff:ffff:ffff:ffff
    Hosts Bits    = 64
    Max. Hosts    = 18446744073709551616   (2^64 - 1)
    Host Range    = { 2001:fe80:abcd:ef::1 - 2001:fe80:abcd:ef:ffff:ffff:ffff:ffff }
    Properties    =
       - 2001:fe80:abcd:ef:: is a NETWORK address
       - Global Unicast Properties:
          + Interface ID = 0000:0000:0000:0000
          + Sol. Node MC = ff02::1:ff00:0000
    GeoIP Country = Unknown (??)
    DNS Hostname  = (Name or service not known)