Network grep “ngrep”

Sometimes it is very practical to use grep, to find a specific regular expression in some files. It would also be very practical to have the grep functionality on the network. This feature is available.

Download ngrep. The package to get is ngrep-1.45.tar.bz2.

To get it to work on a mac do:

tar xvjf ngrep-1.45.tar.bz2
cd ngrep-1.45
./configure --with-pcap-includes=/usr/include --prefix=/usr/local
make
sudo make install

To read the manual page you can run

man ngrep

Now run ngrep itself run

sudo ngrep  <expression to find> <pcap filter expression>

<pcap filter expression> is used the same way as in tcdpdump.

TCP/IP Packet Sniffer

Sometimes you need a powerful sniffer on your system. Every Mac and every Linux system got it. You just have to use it.

tcpdump

The only thing you have to know, are a few flags.

  • -i en0 : Listen on this interface.
  • -n : Don’t resolve hostnames.
  • -nn : Don’t resolve hostnames or port names.
  • -X : Show the contents in both hex and ASCII.
  • -XX : Same as -X, but also shows the ethernet header.
  • -v, -vv, -vvv : Increase the amount of packet information you get back.
  • -c : Get n packets and then stop.
  • -S : Print absolute sequence numbers.
  • -e : Get the ethernet header as well.
  • -q : Show less protocol information.
  • -E : Decrypt IPSEC traffic by providing an encryption key.
  • -s : Set the snaplength, i.e. the amount of data that is being captured in bytes

Example:

If you just want to see some traffic on the interface:

tcpdump -ni en0

If you want get a lot of information:

tcpdump -i en0 -nnvvvXSs 1514

Of course there are some other options. You can record the traffic into a file, read it from a file. You can also set filters on the command line to get only specific packets.

tcpdump -i en1 -nnvvS tcp and src 10.0.5.1 and dst port 5222

Firmware upload with xmodem from a Mac

If you have to upload firmware to a router or a switch with xmodem, get the package lrzsz-0.12.20.tar.gz. Configure it with

tar xvzf lrzsz-0.12.20.tar.gz
cd lrzsz-0.12.20
./configure --disable-nls && sudo make install

Then start a console session with screen

screen /dev/tty.Keyserial1 9600

then, when you are asked from the program up upload the firmware using xmodem, do:

Press ctrl-a
:exec !! lsx -b -X /path/srw2016-24-10086.ros

the upload will start.

Hide your version of BIND

To hide your version of bind, enter the following value to your named.conf

version "[NONE]";

in the option section:

options {
directory "/var/lib/bind";
version "[NONE]";
};

Check the value with this command:

dig @dns.server.tld -c CH -t txt version.bind

Subnet Masks

subnetwork, or subnet, is a logically visible, distinctly addressed part of a single Internet Protocol network. The process of subnetting is the division of a computer network into groups of computers that have a common, designated IP address routing prefix.

/ binary hex decimal
/1 10000000.00000000.00000000.00000000 0×80000000 128.0.0.0
/2 11000000.00000000.00000000.00000000 0xc0000000 192.0.0.0
/3 11100000.00000000.00000000.00000000 0xe0000000 224.0.0.0
/4 11110000.00000000.00000000.00000000 0xf0000000 240.0.0.0
/5 11111000.00000000.00000000.00000000 0xf8000000 248.0.0.0
/6 11111100.00000000.00000000.00000000 0xfc000000 252.0.0.0
/7 11111110.00000000.00000000.00000000 0xfe000000 254.0.0.0
/8 11111111.00000000.00000000.00000000 0xff000000 255.0.0.0
/9 11111111.10000000.00000000.00000000 0xff800000 255.128.0.0
/10 11111111.11000000.00000000.00000000 0xffc00000 255.192.0.0
/11 11111111.11100000.00000000.00000000 0xffe00000 255.224.0.0
/12 11111111.11110000.00000000.00000000 0xfff00000 255.240.0.0
/13 11111111.11111000.00000000.00000000 0xfff80000 255.248.0.0
/14 11111111.11111100.00000000.00000000 0xfffc0000 255.252.0.0
/15 11111111.11111110.00000000.00000000 0xfffe0000 255.254.0.0
/16 11111111.11111111.00000000.00000000 0xffff0000 255.255.0.0
/17 11111111.11111111.10000000.00000000 0xffff8000 255.255.128.0
/18 11111111.11111111.11000000.00000000 0xffffc000 255.255.192.0
/19 11111111.11111111.11100000.00000000 0xffffe000 255.255.224.0
/20 11111111.11111111.11110000.00000000 0xfffff000 255.255.240.0
/21 11111111.11111111.11111000.00000000 0xfffff800 255.255.248.0
/22 11111111.11111111.11111100.00000000 0xfffffc00 255.255.252.0
/23 11111111.11111111.11111110.00000000 0xfffffe00 255.255.254.0
/24 11111111.11111111.11111111.00000000 0xffffff00 255.255.255.0
/25 11111111.11111111.11111111.10000000 0xffffff80 255.255.255.128
/26 11111111.11111111.11111111.11000000 0xffffffc0 255.255.255.192
/27 11111111.11111111.11111111.11100000 0xffffffe0 255.255.255.224
/28 11111111.11111111.11111111.11110000 0xfffffff0 255.255.255.240
/29 11111111.11111111.11111111.11111000 0xfffffff8 255.255.255.248
/30 11111111.11111111.11111111.11111100 0xfffffffc 255.255.255.252
/31 11111111.11111111.11111111.11111110 0xfffffffe 255.255.255.254
/32 11111111.11111111.11111111.11111111 0xffffffff 255.255.255.255