Internet Marketing Forum

Internet Marketing Forum


For Webmasters and Entrepreneurs
|
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 17, 2012, 12:49:22 PM

Login with username, password and session length

Did you ever see an unhappy horse? Did you ever see bird that had the blues? One reason why birds and horses are not unhappy is because they are not trying to impress other birds and horses.


- Dale Carnegie

|-   Internet Marketing Forum > Online Business Discussions > Website Design and Maintenance > Administration
+  

Help with netstat to see which domains are connected to by httpd?

0 Members and 2 Guests are viewing this topic.
Pages: [1] Reply to Thread
Author Topic: Help with netstat to see which domains are connected to by httpd?  (Read 1767 times)
OfflineCode4Gold
Administrator
Code4Gold is a jewel in the roughCode4Gold is a jewel in the roughCode4Gold is a jewel in the roughCode4Gold is a jewel in the rough
Joined: Jan 2006
Posts: 6215


Avatar of Code4Gold

Administrator

View Code4Gold\s ProfileWWW
Gender: MaleGemini United States
notepad Sep 23, 2007, 06:56:04 AM #1
First, I have multiple domains on multiple ips on a server. I was wondering if it's possible to use netstat or some other command to see which domains are being connected to via httpd on a server.

I know netstat -ane will give me something like this

tcp        0      0 66.132.196.93:80            125.162.167.245:3091        ESTABLISHED 99         63514592   
tcp        0      0 66.132.246.171:25           82.43.217.105:4536          ESTABLISHED 47         63514739   
tcp        0      0 66.132.196.93:80            122.164.88.55:25808         TIME_WAIT   0          0         
tcp        0      0 66.132.196.93:80            88.14.120.102:54533         ESTABLISHED 99         63514834   
tcp        0      0 66.132.196.93:80            213.240.205.135:1364        TIME_WAIT   0          0       

Where the fourth column is the IP of the domain being bound to by the IP in the fifth column, but is there a way to do a reverse lookup in the netstat command itself where column four coud contain the hostname intead of just the ip?

I know I can get all the httpd connections out of netstat by doing this

netstat -ane | grep :80

and I can isolate the host ip by using awk in the comand line like this

netstat -ane | grep :80 | awk '{ print $4 }'

but the IP still has :80 tacked onto the end of it, so I do this to get just the ip

netstat -ane | grep :80 | awk '{ print $4 }' | awk '{ sub(/:80/,"");print }'

the problem is when I pipe it into xargs the command blows up if I use dig with -x for reverse lookup as follows

netstat -ane | grep :80 | awk '{ print $4 }' | awk '{ sub(/:80/,"");print }' | xargs -n1 dig -x +short

so I used the deprecated nslookup and grepped "arpa" from the results

netstat -ane | grep :80 | awk '{ print $4 }' | awk '{ sub(/:80/,"");print }' | xargs -n1 nslookup | grep arpa

but this is hideously slow and terribly ugly.....  Is there a more logical way ???










Latest Blog Post : 8 Tips for Creating a Marketing Buzz

Offlinevano
Senior Member
vano is on a distinguished road
Joined: Mar 2007
Posts: 168


Avatar of vano

View vano\s Profile
Gender: MaleGemini Hungary
notepad Sep 28, 2007, 10:24:44 PM #2
You are over my head with those commands. I know a few Linux commands but you are far more advanced than me.
Offlinebeck86
New Member
beck86 is on a distinguished road
Joined: Mar 2009
Posts: 9


Avatar of beck86

View beck86\s Profile
United States
notepad Mar 30, 2009, 12:14:43 AM #3
You need to use the --numeric-ports switch and turn off the -n switch

try

 netstat --numeric-ports -ae | grep :80 | awk '{ print $4 }' | awk '{ sub(/:80/,"");print }'

from the manpage

Quote
--verbose , -v
       Tell  the  user  what  is going on by being verbose. Especially print some useful information
       about unconfigured address families.

   --numeric , -n
       Show numerical addresses instead of trying to determine symbolic host, port or user names.

   --numeric-hosts
       shows numerical host addresses but does not affect the resolution of port or user names.

   --numeric-ports
       shows numerical port numbers but does not affect the resolution of host or user names.

   --numeric-users
       shows numerical user IDs but does not affect the resolution of host or port names.

AWeber - Email Marketing Made Easy
Pages: [1] Reply to Thread


Code4Gold Internet Marketing Forum © 2006-2011 Resdaz Media LLC - All Rights Reserved
Forum Software Powered by SMF - © 2001-2008, Lewis Media. All Rights Reserved.