====== NETWORK - Fu ====== Check to see what is running on a specific port number sudo netstat -tulpn | grep :8080 Showing opened ports on machine netstat -tulpnc List services running on each open port nmap -T Aggressive -A -v 127.0.0.1 -p 1-65000 Ping 10 times then quit ping -c 10 hostname Ping a host until it responds, then play a sound, then exit beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; } Ping a host until it responds, then play a sound, then exit speakwhenup() { [ "$1" ] && PHOST="$1" || return 1; until ping -c1 -W2 $PHOST >/dev/null 2>&1; do sleep 5s; done; espeak "$PHOST is up" >/dev/null 2>&1; } Ping all hosts on 192.168.1.0/24 for i in {0..255} ; do (ping 192.168.1.$i -c 1 > /dev/null && echo "192.168.1.$i" & ) ; done Ping all hosts on 192.168.1.0/24 fping -ga 192.168.1.0/24 2> /dev/null Ping all hosts on 192.168.1.0/24 nmap -sn 192.168.1.0/24 Ping a range of addresses nmap -sP -T Insane 192.168.1.1-254 Ping as traceroute mtr google.com Ping a URL sending output to file and STDOUT ping google.com | tee ping-output.txt Script broadcast-pppoe-discover nmap -T4 --script broadcast-pppoe-discover 192.168.122.0/24 The NMAP command you can use scan for the Conficker virus on your LAN nmap -PN -T4 -p139,445 -n -v --script=smb-check-vulns --script-args safe=1 192.168.0.1-254 Use a decoy while scanning ports to avoid getting caught by the sys admin :9 sudo nmap -sS 192.168.0.10 -D 192.168.0.2 Install NMAP 5.0 ,Short and sweet command to do it sudo wget -c "http://nmap.org/dist/nmap-5.00.tar.bz2" && bzip2 -cd nmap-5.00.tar.bz2 | \ tar xvf - && cd nmap-5.00 && ./configure && make && sudo make install Cleanly list available wireless networks (using iwlist) iwlist wlan0 scan | sed -ne 's#^[[:space:]]*\(Quality=\|Encryption key:\|ESSID:\)#\1#p' -e 's#^[[:space:]]*\(Mode:.*\)$#\1\n#p' Find out what is using the bandwidth nethogs How to speedup the Ethernet device sudo ethtool -s eth0 speed 100 duplex full Obtain ip udhcpc -i eth0 Prevent an IPv6 address on an interface from being used as source address of packets. ip addr change 2001:db8:1:2::ab dev eth0 preferred_lft 0 Traffic stat on ethernet interface ethtool -S eth0 Extraer la MAC del comando ifconfig ifconfig eth0 | grep HW | cut -d " " -f 11 Print machine’s ipv4 addresses echo $(ifconfig) | egrep -o "en.*?inet [^ ]* " | sed 's/.*inet \(.*\)$/\1/' | tail -n +2 Show local IP ifconfig eth0 | grep "inet:" | cut -d ":" -f2 | cut -d " " -f1 Show WAN IP curl ifconfig.me Simple MAC Changeing ifconfig wlan0 hw ether 00:11:22:33:44:55 Display ncurses based network monitor nload -u m eth0 Does a traceroute. Lookup and display the network or AS names and AS numbers. lft -NAS google.com Find installed network devices sudo lshw -C network Find errors and packet loss on network cards ethtool -S eth0 | egrep "(drop|disc|err|fifo|buf|fail|miss|OOB|fcs|full|frags|hdr|tso).*: [^0]" Get contents from hosts, passwd, groups even if they’re in DB/LDAP/other getent [group|hosts|networks|passwd|protocols|services] [keyword] Get current connected wireless network with nm-tools nm-tool 2>/dev/null|sed -n '/Type:[ ]*802.11 WiFi/,/IPv4 Settings/{ /State:[ ]*connected/,/IPv4 Settings/{ s/^[ ]*//;/^\*.*Infra/ { s/^*//;s/:.*//;p } }}' Getting a list of active addresses in your own network. nmap -n -sP -oG - 10.10.10.*/32 | grep ": Up" | cut -d' ' -f2 Highlight network TX, RX information change watch -n 2 -d '/sbin/ifconfig eth0' Identify active network connections lsof -i -P +c 0 +M | grep -i "$1" Investigates the network connection between the host and google public dns server mtr -t -o "LSD NBAW" 8.8.8.8 Make a server’s console beep when the network is down while :; do ping -W1 -c1 -n 8.8.8.8 > /dev/null || tput bel > /dev/console; sleep 1; done MTR command line to show jitter and mimic network traffic sudo mtr -s 1472 -B 0 -oLDRSWNBAWVJMXI IP ADDRESS Netstat -luntp netstat -luntp Network Information ntop Network Interfaces ip link netstat -ie Network throughput test iperf -s Network usage per process sudo nethogs eth0 Nmap list IPs in a network and saves in a txt nmap -sP 192.168.1.0/24 | grep "Nmap scan report for"| cut -d' ' -f 5 > ips.txt Nmap port scanning nmap -v -sT 192.168.0.0/24 One liner to check out CLOSE\_WAIT and TIME\_WAIT connection every five seconds while debugging network apps while true; do netstat -a|grep WAIT|wc -l; sleep 5; done Ping scan for a network and says who is alive or not for i in `seq 254`;do ping -c 1 192.168.10.$i > /dev/null && echo "$i is up"||echo "$i is down";done Ping scanning without nmap for i in {1..254}; do ping -c 1 -W 1 10.1.1.$i | grep 'from'; done Ping scanning without nmap prefix="10.0.0" && for i in `seq 25`; do ping -c 1 $prefix.$i &> /dev/null && echo "Answer from: $prefix.$i" ; done Ping sweep without NMAP prefix="169.254" && for i in {0..254}; do echo $prefix.$i/8; for j in {1..254}; do sh -c "ping -m 1 -c 1 -t 1 $prefix.$i.$j | grep \"icmp\" &" ; done; done Ping with timestamp ping HOSTNAME | while read pong; do echo "$(date): $pong"; done Check the status of a network interface for i in `ls /sys/class/net/`; do echo $i: `cat /sys/class/net/$i/operstate`; done Check the status of a network interface mii-tool [if] Restart network manager sudo /etc/init.d/networking restart Scan computers OS and open services on all network nmap -O 192.168.1.1/24 Scan subnet for used IPs nmap -T4 -sn 192.168.1.0/24 Share internet connection with only one network interface ifconfig eth0:1 192.168.0.1/24 Show alive host on network nmap -sP 192.168.0.* | grep Host | tr "(" ")" | cut -d\) -f2 Show all machines on the network nmap 192.168.0-1.0-255 -sP Show a running count of CLOSE\_WAIT and TIME\_WAIT connections for debugging network apps watch -n5 ss \| grep -c WAIT Show established network connections lsof -i | grep -i estab Simulate slow network connection locally sudo tc qdisc add dev lo root netem delay 500ms Check if network cable is plugged in and working correctly mii-tool eth0 Blink LED Port of NIC Card ethtool -p eth0