Scripts: minor fixes for net* scripts

master
Pierre Neidhardt 2014-01-04 14:45:55 +01:00
parent a54942f07a
commit 474b5afe18
4 changed files with 17 additions and 14 deletions

View File

@ -5,9 +5,7 @@ if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
Usage: ${1##*/} IP Usage: ${1##*/} IP
Print the map of the network associated to the provided IP. Print the map of the network associated to the provided IP.
EOF EOF
exit exit
fi fi

10
.scripts/netscan Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
if ! command -v nmap >/dev/null 2>&1; then
echo >&2 "'nmap' not found in PATH. Exiting."
exit 1
fi
SUBNET="$(ifconfig | awk '/inet/ && $0 !~ "127.0.0.1" {gsub(/\.[0-9]+$/, ".*", $2) ; print $2}')"
echo "Scanning '$SUBNET'..."
nmap -sP "$SUBNET"

View File

@ -1,14 +1,12 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "-h" ]; then if [ "$1" = "-h" ] || [ $# -gt 1 ]; then
cat<<EOF cat<<EOF
Usage: ${0##*/} [INTERFACE] Usage: ${0##*/} [INTERFACE]
Return up and down transmission speed on given interface. If not given, use the Return up and down transmission speed on given interface. If not given, use the
first online interface returned by ifconfig. first online interface returned by ifconfig (lo is ignored).
EOF EOF
exit exit
fi fi
@ -19,15 +17,16 @@ else
fi fi
INTERFACE="$(ifconfig | awk -F: '{print $1; exit}')" INTERFACE="$(ifconfig | grep -vm1 '^lo\|^ \|^$' | cut -f1 -d':')"
if [ -n "$1" ]; then ## AWK alternative
INTERFACE="$1" # ifconfig | awk -F: '!/^ / && !/^$/ && $1!="lo" {print $1;exit}'
fi [ -n "$1" ] && INTERFACE="$1"
if [ ! -d "/sys/class/net/${INTERFACE}" ]; then if [ ! -d "/sys/class/net/${INTERFACE}" ]; then
echo "Error: no such interface (${INTERFACE})." echo "Error: no such interface (${INTERFACE})."
exit exit
fi fi
echo "$INTERFACE"
RX_BEFORE=$(cat /sys/class/net/${INTERFACE}/statistics/rx_bytes) RX_BEFORE=$(cat /sys/class/net/${INTERFACE}/statistics/rx_bytes)
TX_BEFORE=$(cat /sys/class/net/${INTERFACE}/statistics/tx_bytes) TX_BEFORE=$(cat /sys/class/net/${INTERFACE}/statistics/tx_bytes)
@ -40,4 +39,3 @@ TX_RESULT=$(((${TX_AFTER:-0}-${TX_BEFORE:-0})/1024))
echo "RX $RX_RESULT KiB/s" echo "RX $RX_RESULT KiB/s"
echo "TX $TX_RESULT KiB/s" echo "TX $TX_RESULT KiB/s"

View File

@ -50,9 +50,6 @@ alias nox='find . -type f -exec chmod a-x {} +'
## Get your external IP. ## Get your external IP.
command -v curl >/dev/null 2>&1 && alias myip='curl ifconfig.me' command -v curl >/dev/null 2>&1 && alias myip='curl ifconfig.me'
## Network discovery.
command -v nmap >/dev/null 2>&1 && alias network-discover='nmap -sP "192.168.0.*"'
## Prevents accidentally clobbering files. ## Prevents accidentally clobbering files.
alias mkdir='mkdir -p' alias mkdir='mkdir -p'