You are not logged in.

#1 2012-07-15 19:20:01

ResXaoC
Member
From: Nibiru
Registered: 2011-07-17
Posts: 15

Connections.

#/bin/bash
###
# Parses output of lsof for IP-connections and prints in this format: executable, PID, user name, UID, connections of process.
###

r=; b=; e=; n=; compact=

for t in ${@}; do

	[ ${t} = usage   ] && { echo "   ${0} [color] [compact] [usage]"; exit 0; }
	[ ${t} = color   ] && { r="\033[31;1m"; b="\033[34;1m"; e="\033[1m"; n="\033[0m"; }
	[ ${t} = compact ] && compact=1

done

conn=$(lsof -i -F cnuLP)

cmd=; pid=; usr=; uid=; addr=; l_count=; count=0

for t in ${conn}; do
 
	case ${t:0:1} in
		p)   pid=${t:1}; let count++; l_count=${count};;
		c)   cmd=${t:1};;
		u)   uid=${t:1};;
		L)   usr=${t:1};;
		P) proto=${t:1};;
		n)  addr=${t:1}; [ ! -z ${compact} ] && mod="${r}->${n}${e}" || mod="\n\t${r}|${n}\n\t${e}"; addr="${addr/->/${mod}}";;
	esac
 
	[ ! -z ${l_count} ] && printf "${l_count}: "; l_count=
	[ ! -z ${usr}     ] && printf "${cmd} [${e}${pid}${n}] ${b}${usr}${n}:${e}${uid}${n}\n\n"; usr=
	[ ! -z ${addr}    ] && printf "   ${b}${proto}${n}: ${addr}${n}\n\n"; addr=
 
done

30780272.png73261897.png

Last edited by ResXaoC (2012-07-15 20:18:15)

Offline

#2 2012-07-15 19:21:27

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Connections.

some relevant subject other than just a period would be nice


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2012-07-15 19:39:44

ResXaoC
Member
From: Nibiru
Registered: 2011-07-17
Posts: 15

Re: Connections.

Sorry.

Last edited by ResXaoC (2012-07-15 19:45:56)

Offline

Board footer

Powered by FluxBB