Remove trailing whitespace
This commit is contained in:
parent
a8f9e9d65c
commit
953f429f84
@ -1,23 +1,23 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# TP-Link Wi-Fi Smart Plug Protocol Client
|
# TP-Link Wi-Fi Smart Plug Protocol Client
|
||||||
# For use with TP-Link HS-100 or HS-110
|
# For use with TP-Link HS-100 or HS-110
|
||||||
#
|
#
|
||||||
# by Lubomir Stroetmann
|
# by Lubomir Stroetmann
|
||||||
# Copyright 2016 softScheck GmbH
|
# Copyright 2016 softScheck GmbH
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
import socket
|
import socket
|
||||||
import argparse
|
import argparse
|
||||||
@ -30,7 +30,7 @@ def validIP(ip):
|
|||||||
socket.inet_pton(socket.AF_INET, ip)
|
socket.inet_pton(socket.AF_INET, ip)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
parser.error("Invalid IP Address.")
|
parser.error("Invalid IP Address.")
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
# 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
|
||||||
@ -52,18 +52,18 @@ commands = {'info' : '{"system":{"get_sysinfo":{}}}',
|
|||||||
def encrypt(string):
|
def encrypt(string):
|
||||||
key = 171
|
key = 171
|
||||||
result = "\0\0\0\0"
|
result = "\0\0\0\0"
|
||||||
for i in string:
|
for i in string:
|
||||||
a = key ^ ord(i)
|
a = key ^ ord(i)
|
||||||
key = a
|
key = a
|
||||||
result += chr(a)
|
result += chr(a)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def decrypt(string):
|
def decrypt(string):
|
||||||
key = 171
|
key = 171
|
||||||
result = ""
|
result = ""
|
||||||
for i in string:
|
for i in string:
|
||||||
a = key ^ ord(i)
|
a = key ^ ord(i)
|
||||||
key = ord(i)
|
key = ord(i)
|
||||||
result += chr(a)
|
result += chr(a)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ def decrypt(string):
|
|||||||
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="<ip>", required=True, help="Target IP Address", type=validIP)
|
||||||
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")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -85,14 +85,14 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Send command and receive reply
|
# Send command and receive reply
|
||||||
try:
|
try:
|
||||||
sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock_tcp.connect((ip, port))
|
sock_tcp.connect((ip, port))
|
||||||
sock_tcp.send(encrypt(cmd))
|
sock_tcp.send(encrypt(cmd))
|
||||||
data = sock_tcp.recv(2048)
|
data = sock_tcp.recv(2048)
|
||||||
sock_tcp.close()
|
sock_tcp.close()
|
||||||
|
|
||||||
print "Sent: ", cmd
|
print "Sent: ", cmd
|
||||||
print "Received: ", decrypt(data[4:])
|
print "Received: ", decrypt(data[4:])
|
||||||
except socket.error:
|
except socket.error:
|
||||||
|
Loading…
Reference in New Issue
Block a user