Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Ping a port with hping3

# cf. http://trac.macports.org/wiki/InstallingMacPorts
/opt/local/bin/port info hping3
/usr/bin/sudo /opt/local/bin/port install hping3

hping3 --help


# Terminal window 1
alias sudo=/usr/bin/sudo
alias tcpdump=/usr/sbin/tcpdump
#sudo tcpdump -s0 -xX -i lo0 port 4678 and host localhost
sudo tcpdump -s0 -vvv -i lo0 port 4678 and host localhost


# Terminal window 2
alias sudo=/usr/bin/sudo
alias hping3=/opt/local/sbin/hping3
sudo hping3 -I lo0 -s 4678 -c 1 localhost -p 4678
sudo hping3 -S -I lo0 -d 995 -s 4678 -c 1 localhost -p 4678
sudo hping3 -SA -I lo0 -d 995 -w 200 -s 4678 -c 1 localhost -p 4678
sudo hping3 -SA -M 3000 -I lo0 -d 995 -w 65 -s 4678 -c 1 localhost -p 4678
sudo hping3 -DV -SA -I lo0 -s 4678 -a 192.168.1.100 -c 1 localhost -p 4678


#----------------------------------------


# some corresponding ipfw rules for testing purposes 
# (just place them at the beginning of your ipfw rule set)

# not me to me & me to not me
/sbin/ipfw -q add count log all from not me to me 4678 in
/sbin/ipfw -q add count log all from me to not me 4678 out

# any to me & me to any
/sbin/ipfw -q add count log all from any to me 4678 in
/sbin/ipfw -q add count log all from me to any 4678 out
    
# any to any
/sbin/ipfw -q add count log all from any to any 4678

cURL Response Times

Determine response times of a URL with cURL.


echo "`curl -s -o /dev/null -w '%{time_starttransfer}-%{time_pretransfer}' http://www.domain.com/`"|bc

curl -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null -s http://www.domain.com/

Pinging/resolving to the Textdrive IP's

    _______________________________________
________| |_________
\ | davie.textdrive.com | /
\ | | /
\ | "kinda like a little brother" | /
/ |_______________________________________| \
/___________) (___________\



rsimplicio@davie$ ping simplicio.com
PING simplicio.com (207.7.108.101): 56 data bytes
64 bytes from 207.7.108.101: icmp_seq=0 ttl=64 time=0.033 ms
64 bytes from 207.7.108.101: icmp_seq=1 ttl=64 time=0.021 ms
64 bytes from 207.7.108.101: icmp_seq=2 ttl=64 time=0.029 ms
64 bytes from 207.7.108.101: icmp_seq=3 ttl=64 time=0.029 ms