In: Computer Science
Part 1: netstat
Run the 'netstat' command and review the output. Note that the first part
of the output is a list of active Internet connections, and the second part
is a list of active sockets. The format of each part is different (i.e. different
number of columns per line, and different column headers).
1. Write a bash command line that will display the number of active Internet
connections as reported by 'netstat'. Your output should be a single number.
2. Write a bash command line that will display the number of active Internet
connections with non-zero 'Send-Q' values, as reported by 'netstat'. Your
output should be a single number.
3. Write a bash command line that will display the TOTAL of all 'Send-Q' values
for all active Internet connections reported by 'netstat'. In other words,
calculate and display the numeric total of the 'Send-Q' column of the 'netstat'
output. Your output should be a single number.
4. Is the 'Foreign Address' reported by 'netstat' an internal or external address?
Explain why.
5. Write a bash command line that will display the 'I-Node' and 'State' values
for all active UNIX domain sockets whose State is "CONNECTED" and whose "Path"
value is empty (i.e. all spaces)
6. Write a bash command line that will display the 'Type' and 'I-Node' values for
all active UNIX domain sockets whose 'RefCnt' value is greater than 2.
Part 2: hostname
Review the 'man' documentation for 'hostname'.
7. Execute a 'hostname -i' command.
Is the IP address displayed by 'hostname' an internal or an external address?
Explay why.
Part 3: ping
Review the 'man' documetation for 'ping'.
Execute a 'ping www.pcc.edu' command and review the output.
8. Is the IP address shown for www.pcc.edu an internal or an external IP address?
Explain why.
9. Write a bash command line that will ping 'www.pcc.edu' 10 times, and then display
the average ping time in milliseconds. Your output should be a single number.
1. Write a bash command line that will display the number of
active Internet
connections as reported by 'netstat'. Your
output should be a single number.
netstat | grep ESTABLISHED | wc | awk '{ print $1 }'
2. Write a bash command line that will display the number of
active Internet
connections with non-zero 'Send-Q' values, as
reported by 'netstat'. Your
output should be a single number.
netstat | grep ESTABLISHED | awk '{ print $3 }' | grep
-vcw 0
3. Write a bash command line that will display the TOTAL of all
'Send-Q' values
for all active Internet connections reported by
'netstat'. In other words,
calculate and display the numeric total of the
'Send-Q' column of the 'netstat'
output. Your output should be a single
number.
netstat | grep ESTABLISHED | awk '{ print $3 }' | awk -F '|' '{sum+=$NF} END {print sum}'
5. Write a bash command line that will display the 'I-Node' and
'State' values
for all active UNIX domain sockets whose State
is "CONNECTED" and whose "Path"
value is empty (i.e. all spaces)
netstat | grep CONNECTED | awk '{if ($8) print $0;}' |
awk '{ print $6 " " $7 }'
6. Write a bash command line that will display the 'Type' and
'I-Node' values for
all active UNIX domain sockets whose 'RefCnt'
value is greater than 2.
netstat | grep CONNECTED | awk '{if ($2 > 2) print $0;}' | awk '{ print $5 " " $7 }'
9. Write a bash command line that will ping 'www.pcc.edu' 10 times,
and then display
the average ping time in milliseconds. Your
output should be a single number.
ping www.google.com -c 10 | grep rtt | awk '{print
$4}' | cut -d / -f 2