You are not logged in.

#1 2015-09-24 22:09:47

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

Script to check what countries you are connected to

I use it for my status bar.

ss -n -a -t -u |\
	awk '{print $6}' |\
	grep -o '^[0-9]\{2,3\}\.[0-9.]*' |\
	grep -v '^127\.0\.0\.1' |\
        sort -u |\
	parallel 'geoiplookup {}' |\
        sed 's/[^:]*: \([A-Z]*\),.*/\L\1/' |\
	sort -u

Requires the *geoip* package and *parallel*.

Sample output

us
fr
cn

Regards.

EDIT: added a sort -u to avoid looking for the same ip more than once.
EDIT: less processes

Last edited by pepeapepepe (2015-09-26 01:27:59)


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

#2 2015-09-24 23:13:10

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Script to check what countries you are connected to

-a includes -t and -u so you can shorten that call to `ss -an`. Other than that, it doesn't look too bad smile

Offline

#3 2015-09-24 23:58:55

pepeapepepe
Member
From: Buenos Aires, Argentina
Registered: 2009-05-13
Posts: 36

Re: Script to check what countries you are connected to

fukawi2 wrote:

-a includes -t and -u so you can shorten that call to `ss -an`. Other than that, it doesn't look too bad smile

Hi fukawi2,

Thanks for the feedback. It seems that `ss -an` is not equivalent to `ss -n -a -t -u` as I could see using:

diff <(ss -an) <(ss -n -a -t -u)

In particular `-an` seems to be includig other non TCP nor UDP connections (I think).

Cheers.

Last edited by pepeapepepe (2015-09-25 00:01:03)


.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-

Offline

#4 2015-09-25 00:16:37

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Script to check what countries you are connected to

Sorry, you're right. I think what I meant to say was you don't need -a, since only -t and -u will have IP addresses associated with the connection.

Offline

Board footer

Powered by FluxBB