Lookup autonomous systems of all outgoing http/s traffic

ss -t -o state established '( dport = :443 || dport = :80 )'|grep tcp|awk '{ print $5 }'|sed s/:http[s]*//g|sort -u|netcat whois.cymru.com 43|grep -v "AS Name"|sort -t'|' -k3
Sample Output
13335   | 104.25.235.23    | CLOUDFLARENET - CloudFlare, Inc.,US
13335   | 2400:cb00:2048:1::681b:ae68              | CLOUDFLARENET - CloudFlare, Inc.,US
19679   | 162.125.17.131   | DROPBOX - Dropbox, Inc.,US
15169   | 2a00:1450:4013:c01::bd                   | GOOGLE - Google Inc.,US
15169   | 2a00:1450:4016:7::17                     | GOOGLE - Google Inc.,US
15169   | 2a00:1450:4016:804::2005                 | GOOGLE - Google Inc.,US
15169   | 2a00:1450:4016:804::200e                 | GOOGLE - Google Inc.,US
15169   | 2a00:1450:4016:805::200e                 | GOOGLE - Google Inc.,US
13414   | 104.244.42.1     | TWITTER - Twitter Inc.,US

3
By: koppi
2016-04-07 01:48:44

1 Alternatives + Submit Alt

What Others Think

Great idea, doesn't work for me I use:: ss -t -o state established '( dport = :443 || dport = :80 )' | grep -Po '([0-9a-z:.]*)(?=:http[s])' | sort -u|netcat whois.cymru.com 43|grep -v "AS Name"|sort -t'|' -k3 To get tcp use the -t option (tcp/udp isn't printed on older versions of ss) ss -t -o state established '( dport = :443 || dport = :80 )' Some grep versions supports look behind so you can replace awk|sed with: grep -Po '([0-9a-z:.]*)(?=:http[s])'
miniker84 · 118 weeks and 2 days ago
someone told me that grep didn't work for them so there is the much messier sed version: ss -t -o state established '( dport = :443 || dport = :80 )' | sed -r 's/.*?\s([0-9a-z:.]+):http[s]*.*$/\1/;t;d'| sort -u|netcat whois.cymru.com 43|grep -v "AS Name"|sort -t'|' -k3 sed -r 's/.*?\s([0-9a-z:.]+):http[s]*.*$/\1/;t;d'
miniker84 · 118 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: