CLI Handbook¶
Goal¶
This is more or less a personal reference with useful CLI functions and commands.
Generally, everything is tested, but stuff breaks or changes with versions. Feedback or other recommendations are welcome!
The format is still work in progress
and will change over time. Time will tell.
Things I try to focus on: - board tools prefered - one-liners - simplicity - reference to official docs - showing results
Check for open network port on host¶
Linux¶
Note: ss
is being used on modern systems as netstat
is deprecated.
# Specific Port (TCP/UDP)
ss -tupln | grep :443
netstat -tupln | grep :443
or
netstat -anu | grep 51820 # TESTING
Windows¶
Powershell
TESTING
# TCP
Get-NetTCPConnection -State Listen
Get-NetTCPConnection -LocalPort 51820
# UDP
Get-NetUDPEndpoint | Where-Object { $_.LocalPort -eq 51820 }
Command Line
# TCP
netstat -an | findstr LISTENING
netstat -ano | findstr ":51820"
# UDP
netstat -ano -p udp | find ":51820"
TCP Connectivity¶
netcat (Linux)
# LISTENER
nc -l -p 443
# SENDER
nc -vz example.com 443
Test-NetConnection (Windows)
# LISTENER
$l=[Net.Sockets.TcpListener]::new([Net.IPAddress]::Any,443);$l.Start();$c=$l.AcceptTcpClient();$s=$c.GetStream();$b=New-Object byte[] 4096;while(($n=$s.Read($b,0,$b.Length)) -gt 0){[Console]::OpenStandardOutput().Write($b,0,$n)};$s.Close();$c.Close();$l.Stop()
# SENDER
Test-NetConnection -ComputerName "example.com" -Port 443
# SHORT
tnc example.com -port 443
UDP Connectivity¶
A way to check connectivity between hosts via UDP.
Linux - netcat
# LISTENER
nc -u -l -p 51820
# SENDER
echo "hello" | nc -u 192.168.1.50 51820
Windows - Powershell
# LISTENER
$u=New-Object System.Net.Sockets.UdpClient 51820;while($true){$r=$u.Receive([ref]([System.Net.IPEndPoint]::new([System.Net.IPAddress]::Any,0)));[Text.Encoding]::UTF8.GetString($r)|Write-Host}
# SENDER
$u=New-Object System.Net.Sockets.UdpClient; $d=[Text.Encoding]::UTF8.GetBytes("hello");$u.Send($d,$d.Length,"192.168.1.50",51820)
Later, find notes¶
- Firewall logs
- get headers for ssh, etc
- curl, get redirects