summaryrefslogtreecommitdiff
path: root/url_handler/ping_script.py
blob: 30f15e5e5c060eac7a16948073fb2732070853e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
import sys, os, time, subprocess

url = sys.argv[1]
if len(url) % 15 == 0: url += "\0"
while len(url) % 15 != 0: url += "\0"

for i in range(len(url) // 15):
    subprocess.check_call(["ping", "-c", "1", "-p", "64" + "".join("{:02X}".format(ord(x)) for x in url[15*i:15*i+15]), "127.0.0.1"], stdout=subprocess.DEVNULL)

while True:
    out = subprocess.check_output(["ping", "-c", "1", "-p", "65", "127.0.0.1"], stderr=subprocess.STDOUT).decode("utf-8")
    if out.find("icmp_seq=1 ") != -1:
        break
    time.sleep(0.2)

while True:
    out = subprocess.check_output(["ping", "-c", "1", "-p", "66", "127.0.0.1"], stderr=subprocess.STDOUT).decode("utf-8")
    idx = out.find("icmp_seq=")
    idx2 = out.find(" ", idx)
    seqnum = int(out[idx+9:idx2])
    n0 = seqnum % 256
    n1 = seqnum >> 8
    if n0 == 0: break
    print(chr(n0), end="")
    if n1 == 0: break
    print(chr(n1), end="")