Bitcoin Forum
December 08, 2016, 10:08:11 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: « 1 [2]  All
  Print  
Author Topic: HTTP bootstrapping ?  (Read 6054 times)
adulau
Newbie
*
Offline Offline

Activity: 12


View Profile
December 28, 2010, 02:06:45 PM
 #21

Let's just make the final count with awk too...

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.

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



Just to be a little bit picky, the netstat output is slightly different between BSD-like Unix and GNU/Linux.
The port is separated by a dot on the BSD-like Unix. So maybe the pattern matching /:8333/ could be
reviewed to include also the other output... but beside that, this is just fine.


1481191691
Hero Member
*
Offline Offline

Posts: 1481191691

View Profile Personal Message (Offline)

Ignore
1481191691
Reply with quote  #2

1481191691
Report to moderator
1481191691
Hero Member
*
Offline Offline

Posts: 1481191691

View Profile Personal Message (Offline)

Ignore
1481191691
Reply with quote  #2

1481191691
Report to moderator
1481191691
Hero Member
*
Offline Offline

Posts: 1481191691

View Profile Personal Message (Offline)

Ignore
1481191691
Reply with quote  #2

1481191691
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481191691
Hero Member
*
Offline Offline

Posts: 1481191691

View Profile Personal Message (Offline)

Ignore
1481191691
Reply with quote  #2

1481191691
Report to moderator
1481191691
Hero Member
*
Offline Offline

Posts: 1481191691

View Profile Personal Message (Offline)

Ignore
1481191691
Reply with quote  #2

1481191691
Report to moderator
1481191691
Hero Member
*
Offline Offline

Posts: 1481191691

View Profile Personal Message (Offline)

Ignore
1481191691
Reply with quote  #2

1481191691
Report to moderator
pj
Newbie
*
Offline Offline

Activity: 24


View Profile
December 28, 2010, 02:15:24 PM
 #22


Just to be a little bit picky, the netstat output is slightly different between BSD-like Unix and GNU/Linux.
The port is separated by a dot on the BSD-like Unix. So maybe the pattern matching /:8333/ could be
reviewed to include also the other output... but beside that, this is just fine.
Well, darn.

Could you provide a sample few lines of output from a BSD netstat -an?

It would take more than changing the /:8333/ pattern to fix this, if I understand your description
correctly.  There is also the awk split on the ":" which would have to be fixed as well.  This is all
doable with a little bit of regular expression hacking (something I do easily.)  But I should see the
exact BSD netstat -an output first, to be sure I understand it correctly.
adulau
Newbie
*
Offline Offline

Activity: 12


View Profile
December 28, 2010, 02:35:43 PM
 #23


Just to be a little bit picky, the netstat output is slightly different between BSD-like Unix and GNU/Linux.
The port is separated by a dot on the BSD-like Unix. So maybe the pattern matching /:8333/ could be
reviewed to include also the other output... but beside that, this is just fine.
Well, darn.

Could you provide a sample few lines of output from a BSD netstat -an?

It would take more than changing the /:8333/ pattern to fix this, if I understand your description
correctly.  There is also the awk split on the ":" which would have to be fixed as well.  This is all
doable with a little bit of regular expression hacking (something I do easily.)  But I should see the
exact BSD netstat -an output first, to be sure I understand it correctly.


I think this could do the trick in awk for the matching :  && (/:8333/ || /\.8333/)
and for the split, an if block to match the : and another if block to split on dot. It
will start to be unreadable for an one-liner ;-)

FYI, here is output:

Code:
tcp4       0    116  192.168.1.2.8333       80.217.82.59.45167     ESTABLISHED
tcp4       0      0  192.168.1.2.8333       68.103.101.19.29297    ESTABLISHED
tcp4       0      0  192.168.1.2.8333       79.184.79.110.1191     ESTABLISHED
tcp4       0      0  192.168.1.2.8333       61.94.216.38.10100     ESTABLISHED
tcp4       0      0  192.168.1.2.8333       113.22.164.48.10020    ESTABLISHED
tcp4       0      0  192.168.1.2.8333       85.232.113.117.8597    ESTABLISHED
tcp4       0      0  192.168.1.2.8333       46.109.12.201.3328     ESTABLISHED
tcp4       0      0  192.168.1.2.8333       62.103.58.117.3230     ESTABLISHED

pj
Newbie
*
Offline Offline

Activity: 24


View Profile
December 28, 2010, 02:53:55 PM
 #24

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." }
    '
grondilu
Legendary
*
Offline Offline

Activity: 1134


View Profile
December 28, 2010, 03:14:55 PM
 #25

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.
pj
Newbie
*
Offline Offline

Activity: 24


View Profile
December 28, 2010, 03:34:28 PM
 #26

Code:
    ...
   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' |
    ...

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.

But sed -r is not available on all sed commands.  I wanted something portable.  Granted, I have no example of a sed command that presently lacks it.  I just know that extended regular expression support was added (to sed and anything else) sometime after such commands first existed, so I studiously avoid using extended regular expressions in situations where portability to unknown runtime environments is desired.

If one uses sed -r, then I suppose a better (well, shorter anyway) expression would be:
Code:
sed -r 's/(([0-9]+\.){3}[0-9])\.([0-9])/\1:\3/g'
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!