Scripts: minor fixes for net* scripts
parent
a54942f07a
commit
474b5afe18
|
@ -5,9 +5,7 @@ if [ $# -ne 1 ] || [ "$1" = "-h" ] ; then
|
|||
Usage: ${1##*/} IP
|
||||
|
||||
Print the map of the network associated to the provided IP.
|
||||
|
||||
EOF
|
||||
|
||||
exit
|
||||
fi
|
||||
|
||||
|
|
|
@ -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"
|
|
@ -1,14 +1,12 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ "$1" = "-h" ]; then
|
||||
if [ "$1" = "-h" ] || [ $# -gt 1 ]; then
|
||||
cat<<EOF
|
||||
Usage: ${0##*/} [INTERFACE]
|
||||
|
||||
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
|
||||
|
||||
exit
|
||||
fi
|
||||
|
||||
|
@ -19,15 +17,16 @@ else
|
|||
fi
|
||||
|
||||
|
||||
INTERFACE="$(ifconfig | awk -F: '{print $1; exit}')"
|
||||
if [ -n "$1" ]; then
|
||||
INTERFACE="$1"
|
||||
fi
|
||||
INTERFACE="$(ifconfig | grep -vm1 '^lo\|^ \|^$' | cut -f1 -d':')"
|
||||
## AWK alternative
|
||||
# ifconfig | awk -F: '!/^ / && !/^$/ && $1!="lo" {print $1;exit}'
|
||||
[ -n "$1" ] && INTERFACE="$1"
|
||||
|
||||
if [ ! -d "/sys/class/net/${INTERFACE}" ]; then
|
||||
echo "Error: no such interface (${INTERFACE})."
|
||||
exit
|
||||
fi
|
||||
echo "$INTERFACE"
|
||||
|
||||
RX_BEFORE=$(cat /sys/class/net/${INTERFACE}/statistics/rx_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 "TX $TX_RESULT KiB/s"
|
||||
|
||||
|
|
|
@ -50,9 +50,6 @@ alias nox='find . -type f -exec chmod a-x {} +'
|
|||
## Get your external IP.
|
||||
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.
|
||||
alias mkdir='mkdir -p'
|
||||
|
||||
|
|
Loading…
Reference in New Issue