From 2819a565dc84af833b46a194a138ae74555230e7 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Sun, 6 Dec 2015 22:50:24 -0500 Subject: [PATCH] allow setting USER_AGENT --- wattsup.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/wattsup.py b/wattsup.py index 647e56a..2b48bad 100755 --- a/wattsup.py +++ b/wattsup.py @@ -140,7 +140,7 @@ def setNetworkBasic (self, ip_addr, gateway, dns1, dns2, net_mask, dhcp): self.s.write(commands['write_network'].encode('ascii')) self.s.readline() - def setNetworkExtended (self, url, port, pfile, interval=1): + def setNetworkExtended (self, url, port, pfile, uagent, interval=1): if len(url) > 40: print("POST URL too long. Must be 40 characters or less.") sys.exit(1) @@ -149,7 +149,7 @@ def setNetworkExtended (self, url, port, pfile, interval=1): sys.exit(1) cmd = commands['set_network_ext'].format(url, port, pfile, - USER_AGENT, int(interval)).encode('ascii') + uagent, int(interval)).encode('ascii') self.s.write(cmd) self.s.readline() self.s.write(commands['write_network'].encode('ascii')) @@ -264,6 +264,10 @@ def reset (self): nargs=3, help='Configure POST settings. \ ') + parser.add_argument('-u', '--user-agent', + dest='useragent', + help='Set a custom User Agent. Only has effect if -n \ +is also used.') parser.add_argument('--dhcp', dest='dhcp', action='store_true', @@ -321,12 +325,15 @@ def reset (self): url = args.network[0][0] port = args.network[0][1] pfile = args.network[0][2] + uagent = USER_AGENT + if args.useragent: + uagent = args.useragent interval = 1 if args.interval: interval = int(args.interval) - meter.setNetworkExtended(url, port, pfile, interval) + meter.setNetworkExtended(url, port, pfile, uagent, interval) elif args.dhcp: meter.enableDHCP()