From 51f400fe598165e99aa4f5d46d470ae3e329461c Mon Sep 17 00:00:00 2001 From: Sebastian <379651+czarly@users.noreply.github.com> Date: Sun, 3 Nov 2024 08:55:57 +0100 Subject: [PATCH] find me the gateway ips --- utils/capture-ips.sh | 13 +++++++++ utils/compare_blocks2.py | 63 ++++++++++++++++++++++++++++++++++++++++ utils/locate-ips.sh | 27 +++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100755 utils/capture-ips.sh create mode 100644 utils/compare_blocks2.py create mode 100755 utils/locate-ips.sh diff --git a/utils/capture-ips.sh b/utils/capture-ips.sh new file mode 100755 index 00000000..fce6d889 --- /dev/null +++ b/utils/capture-ips.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +ip="$(curl -s ipinfo.io/ip)" +interface="$(ip addr | awk -v ip="$ip" '$1 == "inet" && $2 ~ "^" ip "/" {print $NF}')" + +TMPFILE=$(mktemp) + +timeout 10 tcpdump -i $interface "port ${1:-3042}" -n -q 2> /dev/null | awk '{print $3}' | cut -d '.' -f1-4 | grep -v "$ip" > $TMPFILE +RESULT=$(cat $TMPFILE | sort -u | grep -v '^$') + +rm "$TMPFILE" + +echo "$RESULT" diff --git a/utils/compare_blocks2.py b/utils/compare_blocks2.py new file mode 100644 index 00000000..3fcb71f4 --- /dev/null +++ b/utils/compare_blocks2.py @@ -0,0 +1,63 @@ +import requests +import json + +def get_block_by_number(endpoint, block_number): + hex_block_number = hex(block_number) + response = requests.post( + endpoint, + headers={"Content-Type": "application/json"}, + data=json.dumps({"jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": [hex_block_number, False], "id": 1}) + ) + response_data = response.json() + return response_data['result'] + +def find_highest_matching_block(endpoint1, endpoint2, start_block): + low = 0 + high = start_block + highest_matching_block = None + highest_matching_hash = None + + while low <= high: + mid = (low + high) // 2 + + block1 = get_block_by_number(endpoint1, mid) + block2 = get_block_by_number(endpoint2, mid) + + if block1 is None or block2 is None: + print(f"Block {mid} not found in one of the endpoints") + high = mid - 1 + continue + + if block1['hash'] == block2['hash']: + highest_matching_block = mid + highest_matching_hash = block1['hash'] + low = mid + 1 + else: + high = mid - 1 + + if highest_matching_block is not None: + # Linear search upwards from the highest known matching block to find the highest matching block + while True: + next_block1 = get_block_by_number(endpoint1, highest_matching_block + 1) + next_block2 = get_block_by_number(endpoint2, highest_matching_block + 1) + if next_block1 is None or next_block2 is None or next_block1['hash'] != next_block2['hash']: + break + highest_matching_block += 1 + highest_matching_hash = next_block1['hash'] + + print(f"Matching block found at height {highest_matching_block}") + print(f"Matching block hash: {highest_matching_hash}") + print("I did it!") + + if next_block1 is not None and next_block2 is not None: + print(f"Following block number {highest_matching_block + 1} does not match") + print(f"Endpoint1 hash: {next_block1['hash']}") + print(f"Endpoint2 hash: {next_block2['hash']}") + else: + print("No matching blocks found") + +if __name__ == "__main__": + endpoint1 = "https://rpc-de-15.stakesquid.eu/base" + endpoint2 = "https://mainnet.base.org" + start_block = 7945476 + find_highest_matching_block(endpoint1, endpoint2, start_block) diff --git a/utils/locate-ips.sh b/utils/locate-ips.sh new file mode 100755 index 00000000..3ecccd26 --- /dev/null +++ b/utils/locate-ips.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Temporary file to store results +temp_file=$(mktemp) + +# Loop through each IP from stdin, fetch geolocation, and append data +while read -r ip; do + # Check if the IP is not empty + if [[ -n "$ip" ]]; then + # Fetch geolocation data + response=$(curl -s "https://ipinfo.io/$ip/json") + + # Extract country code, city, and hoster (if available) + country=$(echo "$response" | jq -r '.country // "Unknown"') + city=$(echo "$response" | jq -r '.city // "Unknown"') + hoster=$(echo "$response" | jq -r '.org // "Unknown"') + + # Write the IP and its details to the temp file + echo "$ip - $city, $country, $hoster" >> "$temp_file" + fi +done + +# Output the results +cat "$temp_file" + +# Clean up +rm -f "$temp_file"