Skip to content

Commit ef0b394

Browse files
peektwicejacob-baines
authored andcommitted
Update wppcmd_version.py (#5)
Converted to Python3, also added a condition for the script to do nothing if the socket times out.
1 parent a92968e commit ef0b394

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

crestron/am-100/wppcmd_version.py

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# The script should work on a number of vendors but Crestron seems to be the most popular.
44
#
55
# Sample usage:
6-
#
6+
#
77
# albinolobster@ubuntu:~/poc/crestron$ python wppcmd_version.py -i 192.168.1.88
88
# [+] Attempting connection to 192.168.1.88:389
99
# [+] Connected!
@@ -15,7 +15,8 @@
1515
import struct
1616
import sys
1717
import time
18-
18+
import select
19+
1920
top_parser = argparse.ArgumentParser(description='')
2021
top_parser.add_argument('-i', '--ip', action="store", dest="ip", required=True, help="The IPv4 address to connect to")
2122
top_parser.add_argument('-p', '--port', action="store", dest="port", type=int, help="The port to connect to", default="389")
@@ -24,31 +25,38 @@
2425

2526
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2627
sock.settimeout(5)
27-
print "[+] Attempting connection to " + args.ip + ":" + str(args.port)
28+
print ("[+] Attempting connection to " + args.ip + ":" + str(args.port))
2829
sock.connect((args.ip, args.port))
29-
print "[+] Connected!"
30-
31-
wppcmd = "wppcmd\x00\x00\x90"
30+
print ("[+] Connected!")
31+
32+
wppcmd = bytes('wppcmd', 'utf-8') + bytes.fromhex('000090')
33+
sock.setblocking(0)
3234
sock.sendall(wppcmd)
33-
34-
resp = sock.recv(1024)
35-
36-
if len(resp) == 0x89 and resp.startswith("wppcmd\x00\x00\x91AWPP") == True:
37-
ip = resp[0x0d:0x12]
38-
hostname = resp[0x19:0x41]
39-
hostname = hostname.strip()
40-
brand = resp[0x41:0x48]
41-
brand = brand.strip()
42-
version = resp[0x7b:0x7f]
43-
converted_ip = str(ord(ip[0])) + '.' + \
44-
str(ord(ip[1])) + '.' + \
45-
str(ord(ip[2])) + '.' + \
46-
str(ord(ip[3]))
47-
converted_version = str(ord(version[0])) + '.' + \
48-
str(ord(version[1])) + '.' + \
49-
str(ord(version[2])) + '.' + \
50-
str(ord(version[3]))
51-
52-
print converted_ip + "," + hostname + "," + brand + "," + converted_version
53-
54-
sock.close()
35+
36+
ready = select.select([sock], [], [], 5)
37+
38+
if ready[0]:
39+
resp = sock.recv(1024)
40+
41+
if len(resp) == 0x89 and resp.startswith(bytes("wppcmd", 'utf-8')) == True:
42+
ip = resp[0x0d:0x12]
43+
hostname = resp[0x19:0x41]
44+
hostname = hostname.rstrip(b' \t\r\n\0')
45+
brand = resp[0x41:0x48]
46+
brand = brand.rstrip(b' \t\r\n\0')
47+
version = resp[0x7b:0x7f]
48+
converted_ip = str(ip[0]) + '.' + \
49+
str(ip[1]) + '.' + \
50+
str(ip[2]) + '.' + \
51+
str(ip[3])
52+
converted_version = str(version[0]) + '.' + \
53+
str(version[1]) + '.' + \
54+
str(version[2]) + '.' + \
55+
str(version[3])
56+
57+
print(converted_ip)
58+
print(str(hostname, 'utf-8'))
59+
print(str(brand, 'utf-8'))
60+
print(converted_version)
61+
62+
sock.close()

0 commit comments

Comments
 (0)