dumpclients: possibilité de choisir les champs supplémentaires à afficher
This commit is contained in:
parent
85c63105ee
commit
abc4cb955d
59
dumpclients
59
dumpclients
|
@ -19,15 +19,18 @@ OPTIONS
|
|||
seules les sockets ouvertes sont affichées.
|
||||
-n, --numeric
|
||||
Afficher uniquement les adresses IP au lieu du nom d'hôte.
|
||||
-z, --zport
|
||||
Ne pas exiger que le port soit spécifié"
|
||||
-z, --allow-no-port
|
||||
Ne pas exiger que le port soit spécifié
|
||||
--show none,ip,port,state
|
||||
Spécifier d'afficher comme informations supplémentaire: rien, l'adresse
|
||||
ip, le port et/ou l'état. Par défaut, afficher le port et l'état."
|
||||
}
|
||||
|
||||
function filter_proto() {
|
||||
case "$1" in
|
||||
tcp) awk '$1 == "tcp" { print }';;
|
||||
tcp6) awk '$1 == "tcp6" { print }';;
|
||||
*) cat;;
|
||||
*) awk 'NR > 2 { print }';;
|
||||
esac
|
||||
}
|
||||
|
||||
|
@ -40,15 +43,27 @@ function filter_port() {
|
|||
}
|
||||
|
||||
function print_conn() {
|
||||
awk '{ client = $5; sub(/:[^:]+$/, "", client); print client " " $6 }'
|
||||
awkrun show_ip:int="$1" show_port:int="$2" show_state:int="$3" '{
|
||||
match($5, /:[^:]+$/)
|
||||
client = substr($5, 1, RSTART - 1)
|
||||
port = substr($5, RSTART + 1)
|
||||
state = $6
|
||||
|
||||
line = client
|
||||
if (show_ip) line = line " " client
|
||||
if (show_port) line = line " " port
|
||||
if (show_state) line = line " " state
|
||||
|
||||
print line
|
||||
}'
|
||||
}
|
||||
|
||||
function print_host() {
|
||||
local -a hosts
|
||||
if [ -n "$*" ]; then
|
||||
while read count ip state; do
|
||||
while read count ip suppl; do
|
||||
resolv_hosts hosts "$ip"
|
||||
echo "$count" "${hosts:-$ip}" "$state"
|
||||
echo "$count ${hosts:-$ip} $suppl"
|
||||
done
|
||||
else
|
||||
cat
|
||||
|
@ -58,23 +73,47 @@ function print_host() {
|
|||
proto=
|
||||
all=
|
||||
resolve=1
|
||||
zport=
|
||||
allow_no_port=
|
||||
suppls=()
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with display_help' \
|
||||
-4,--only-tcp proto=tcp \
|
||||
-6,--only-tcp6 proto=tcp6 \
|
||||
-a,--all all=1 \
|
||||
-n,--numeric resolve= \
|
||||
-z,--zport zport=1 \
|
||||
-z,--allow-no-port allow_no_port=1 \
|
||||
--show: suppls \
|
||||
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
||||
|
||||
port="$1"
|
||||
[ -n "$port" -o -n "$zport" ] || die "Vous devez spécifier le port ou utiliser -z"
|
||||
[ -n "$port" -o -n "$allow_no_port" ] || die "Vous devez spécifier le port ou utiliser -z"
|
||||
|
||||
# déterminer les informations supplémentaires à afficher
|
||||
show_ip=
|
||||
show_port=
|
||||
show_state=
|
||||
array_fix_paths suppls ,
|
||||
anysuppl=
|
||||
for suppl in "${suppls[@]}"; do
|
||||
case "$suppl" in
|
||||
none|n) ;;
|
||||
ip|i) show_ip=1;;
|
||||
port|p) show_port=1;;
|
||||
state|s) show_state=1;;
|
||||
*) ewarn "$suppl: valeur non reconnue";;
|
||||
esac
|
||||
anysuppl=1
|
||||
done
|
||||
[ -n "$anysuppl" ] || {
|
||||
show_port=1
|
||||
show_state=1
|
||||
}
|
||||
|
||||
# afficher les connexions
|
||||
LANG=C netstat -tn ${all:+-a} |
|
||||
filter_proto "$proto" |
|
||||
filter_port "$port" |
|
||||
print_conn |
|
||||
print_conn "$show_ip" "$show_port" "$show_state" |
|
||||
csort |
|
||||
"$scriptdir/umatch" -c -F "" |
|
||||
print_host $resolve
|
||||
|
|
Loading…
Reference in New Issue