Networking

Show internal IP address


On Mac

# IPv4
ifconfig en0 | grep -oE "inet ([^ ]+)" | cut -d " " -f 2
# IPv6
ifconfig en0 | grep -oE "inet6 ([^ ]+)" | cut -d " " -f 2

On Linux (Debian)

# IPv4
ip addr show enp4s0 | grep -oE "inet ([^/]+)" | cut -d " " -f 2
# IPv6
ip addr show enp4s0 | grep -oE "inet6 ([^/]+)" | cut -d " " -f 2

Show default gateway


On Mac

netstat -nr

On Linux (Debian)

ip route show default

Show public IP address

curl ifconfig.me/ip

Show DNS records

dig docs.ar2pi.net +nostats +nocomments +nocmd

Show open ports

lsof -i :8000 | grep "(LISTEN)" # list processes listening on port 8000

netcat

TCP

# sh 1
nc -l 3456
# sh 2
nc localhost 3456
# type in 'hello world'

Open http://localhost:3456 and look at request headers sent to sh 1

HTTP w/ netcat

printf 'GET / HTTP/1.1\r\nHost: ar2pi.github.com\r\n\r\n' | nc -N ar2pi.github.com 80 > response.html

Redirect through netcat

printf 'HTTP/1.1 302 Moved\r\nLocation: https://docs.ar2pi.net/' | nc -N -l 3456

Open http://localhost:3456 and witness redirect

tcpdump

# sh 1
sudo tcpdump -n port 80
# sh 2
printf 'GET / HTTP/1.1\r\nHost: ar2pi.github.com\r\n\r\n' | nc -N ar2pi.github.com 80

traceroute

traceroute -T -p 80 ar2pi.github.com

nmap

sudo nmap -sS -p 8000 -Pn -n --open 192.168.0.13/24

socat

socat tcp-listen:8001,reuseaddr,fork tcp:192.168.0.1:8000