Post
Topic
Board Development & Technical Discussion
Re: HTTP bootstrapping ?
by
grondilu
on 28/12/2010, 15:14:55 UTC
Ok - thanks for the BSD sample output.

How about this code then:

Code:
#!/bin/sh
# Display foreign IP addresses coming from port 8333 --or-- connected to local port 8333.
# Append line at end with date and count of addresses displayed.
#
# GNU Linux netstat separates port numbers from IP addrs using colon ':',
# whereas BSD netstat separates them using a period '.'.  The sed line
# below converts the BSD '.' to a ':', to make it easier for awk to
# split off the port.

netstat -an |
    sed 's/\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)\.\([0-9][0-9]*\)/\1:\2/g' |
    awk -v date="$(date)" '
        $6 == "ESTABLISHED" && /:8333/ { split($5, a, ":"); print a[1] ; n++ }
        END { print "# " date " : " n " bitcoin clients seen." }
    '

omg your regex is ugly.

Code:
    sed -r 's/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\.([0-9]+)/\1:\2/g' |

And I'm pretty sure there is better.