Merge 04a4b7cf81
into a8f9e9d65c
This commit is contained in:
commit
d25b479c7f
1 changed files with 22 additions and 21 deletions
|
@ -21,16 +21,17 @@
|
||||||
#
|
#
|
||||||
import socket
|
import socket
|
||||||
import argparse
|
import argparse
|
||||||
|
import struct
|
||||||
|
|
||||||
version = 0.1
|
version = 0.1
|
||||||
|
|
||||||
# Check if IP is valid
|
# Check if hostname is valid
|
||||||
def validIP(ip):
|
def validHostname(hostname):
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET, ip)
|
socket.gethostbyname(hostname)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
parser.error("Invalid IP Address.")
|
parser.error("Invalid hostname.")
|
||||||
return ip
|
return hostname
|
||||||
|
|
||||||
# Predefined Smart Plug Commands
|
# Predefined Smart Plug Commands
|
||||||
# For a full list of commands, consult tplink_commands.txt
|
# For a full list of commands, consult tplink_commands.txt
|
||||||
|
@ -51,7 +52,7 @@ commands = {'info' : '{"system":{"get_sysinfo":{}}}',
|
||||||
# XOR Autokey Cipher with starting key = 171
|
# XOR Autokey Cipher with starting key = 171
|
||||||
def encrypt(string):
|
def encrypt(string):
|
||||||
key = 171
|
key = 171
|
||||||
result = "\0\0\0\0"
|
result = struct.pack(">I", len(string))
|
||||||
for i in string:
|
for i in string:
|
||||||
a = key ^ ord(i)
|
a = key ^ ord(i)
|
||||||
key = a
|
key = a
|
||||||
|
@ -69,7 +70,7 @@ def decrypt(string):
|
||||||
|
|
||||||
# Parse commandline arguments
|
# Parse commandline arguments
|
||||||
parser = argparse.ArgumentParser(description="TP-Link Wi-Fi Smart Plug Client v" + str(version))
|
parser = argparse.ArgumentParser(description="TP-Link Wi-Fi Smart Plug Client v" + str(version))
|
||||||
parser.add_argument("-t", "--target", metavar="<ip>", required=True, help="Target IP Address", type=validIP)
|
parser.add_argument("-t", "--target", metavar="<hostname>", required=True, help="Target hostname or IP address", type=validHostname)
|
||||||
group = parser.add_mutually_exclusive_group(required=True)
|
group = parser.add_mutually_exclusive_group(required=True)
|
||||||
group.add_argument("-c", "--command", metavar="<command>", help="Preset command to send. Choices are: "+", ".join(commands), choices=commands)
|
group.add_argument("-c", "--command", metavar="<command>", help="Preset command to send. Choices are: "+", ".join(commands), choices=commands)
|
||||||
group.add_argument("-j", "--json", metavar="<JSON string>", help="Full JSON string of command to send")
|
group.add_argument("-j", "--json", metavar="<JSON string>", help="Full JSON string of command to send")
|
||||||
|
|
Loading…
Add table
Reference in a new issue