Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- try:
- import paho.mqtt.client as mqtt
- except:
- exit("[+]Error: Could not import paho mqtt! Did you install it? pip install paho-mqtt")
- import json
- import sys
- import time
- if len(sys.argv) <=1:
- exit("Usage: ./owntrack.py TARGETIP")
- def on_connect(client, userdata, rc):
- print("Connected with result code "+str(rc))
- # Subscribing in on_connect() means that if we lose the connection and
- # reconnect then subscriptions will be renewed.
- # Subscribing to "#" will enumerate ALL tree data...be careful with this!
- # Note: Subscribing to $SYS will yield statistical data.
- client.subscribe("owntracks/#")
- def on_message(client, userdata, msg):
- try:
- #print msg.topic+" "+str(msg.payload.decode('utf-8'))
- msgout = str(msg.payload.decode('utf-8'))
- data = json.loads(msgout)
- epochtime = data['tst']
- ptime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(epochtime))
- ptime = str(ptime)
- acc = data['acc']
- acc = str(acc)
- lat = data['lat']
- lat = str(lat)
- lon = data['lon']
- lon = str(lon)
- print "--------"
- print "Account ID: ", acc
- print "Check-in: ", ptime
- print "Latitude: ", lat
- print "Longitude: ", lon
- print "--------"
- except Exception as e:
- pass
- target = sys.argv[1]
- client = mqtt.Client(client_id="5D41402ABC4B2A76B9719D911017C592")
- client.on_connect = on_connect
- client.on_message = on_message
- client.connect(target, 1883, 60)
- # Blocking call that processes network traffic, dispatches callbacks and
- # handles reconnecting.
- # Other loop*() functions are available that give a threaded interface and a
- # manual interface.
- client.loop_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement