Created
October 12, 2017 12:30
-
-
Save mraerino/e64394c24d722d2cb3c18d573e8c6474 to your computer and use it in GitHub Desktop.
Initial a bare Viprinet router without the need to execute a Windows binary
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 python3 | |
import socket | |
import sys | |
import ipaddress | |
# setup sockets | |
sendsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
sendsock.bind(("169.254.54.81",6000)) | |
sendsock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
recvsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
recvsock.bind(("",5000)) | |
recvsock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
# discover | |
sendsock.sendto(b"VIPRINET\x04\x00", ("255.255.255.255", 5000)) | |
# get answer | |
recvsock.recvfrom(1) | |
data, addr = recvsock.recvfrom(1024) | |
print(data) | |
# disasemble answer | |
brand = data[0:8].decode("utf-8") | |
if brand != "VIPRINET": | |
print("Wrong brand") | |
sys.exit(1) | |
if not (data[8] == 4 and data[9] == 1): | |
print("Wrong action") | |
sys.exit(1) | |
serial = data[11:28].decode("utf-8") | |
print("Serial:", serial) | |
# change ip | |
msg = "" | |
msg += brand | |
msg += "\x04\x02" | |
msg += serial | |
iface = ipaddress.IPv4Interface(sys.argv[1]) | |
ip = iface.ip | |
netmask = ipaddress.IPv4Address(iface.network.netmask) | |
packet = msg.encode() | |
packet += ip.packed | |
packet += netmask.packed | |
sendsock.sendto(packet, ("255.255.255.255", 5000)) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment