-
-
Save lontivero/b3e7ae0e6d7a76e7b6388a24d657f706 to your computer and use it in GitHub Desktop.
dumps Bitcoin network traffic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# bitdump.sh | |
# | |
# captures Bitcoin network traffic | |
SELF=`basename $0` | |
if [[ $1 = "" ]]; then | |
DEFAULT="en1" | |
echo "$SELF: no interface name provided as argument: using $DEFAULT as default" | |
else | |
DEFAULT=$1 | |
fi | |
connected_nodes() { | |
netstat -an | | |
awk '/8333/ && /ESTA/ { print $5 }' | | |
sed 's/[.:]8333//' | |
} | |
# tcpdump config | |
IF="-i $DEFAULT" | |
ASCII="-A" | |
BINARY="-XX" | |
NO_DNS="-n" | |
FULL_PACKETS="-s 0" | |
NODES=($(connected_nodes)) | |
PORT="8333" | |
FILE="bitdump.pcap" | |
if [[ -z "$NODES" ]]; then | |
echo "$SELF: No peer found, check your internet connection and that Bitcoin is running" | |
else | |
for (( i = 0; i < ${#NODES[*]}; i++ )); do | |
ANY_NODE="host ${NODES[i]} and $ANY_NODE" | |
done | |
# -t : don't print a timestamp on each dump line | |
# -q : stay quiet | |
CMD="tcpdump $IF -w $FILE $FULL_PACKETS $BINARY $NO_DNS $ANY_NODE port $PORT" | |
echo $CMD | |
$CMD | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment