SHARE
TWEET

owntracks

protoxin Mar 2nd, 2017 991 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. try:
  4.     import paho.mqtt.client as mqtt
  5. except:
  6.     exit("[+]Error: Could not import paho mqtt! Did you install it? pip install paho-mqtt")
  7. import json
  8. import sys
  9. import time
  10.  
  11. if len(sys.argv) <=1:
  12.     exit("Usage: ./owntrack.py TARGETIP")
  13.  
  14. def on_connect(client, userdata, rc):
  15.     print("Connected with result code "+str(rc))
  16.     # Subscribing in on_connect() means that if we lose the connection and
  17.     # reconnect then subscriptions will be renewed.
  18.  
  19.     # Subscribing to "#" will enumerate ALL tree data...be careful with this!
  20.     # Note: Subscribing to $SYS will yield statistical data.
  21.     client.subscribe("owntracks/#")
  22. def on_message(client, userdata, msg):
  23.     try:
  24.         #print msg.topic+" "+str(msg.payload.decode('utf-8'))
  25.         msgout = str(msg.payload.decode('utf-8'))
  26.         data = json.loads(msgout)
  27.         epochtime = data['tst']
  28.         ptime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(epochtime))
  29.         ptime = str(ptime)
  30.         acc = data['acc']
  31.         acc = str(acc)
  32.         lat = data['lat']
  33.         lat = str(lat)
  34.         lon = data['lon']
  35.         lon = str(lon)
  36.         print "--------"
  37.         print "Account ID: ", acc
  38.         print "Check-in: ", ptime
  39.         print "Latitude: ", lat
  40.         print "Longitude: ", lon
  41.         print "--------"
  42.     except Exception as e:
  43.         pass
  44.  
  45. target = sys.argv[1]
  46.  
  47. client = mqtt.Client(client_id="5D41402ABC4B2A76B9719D911017C592")
  48. client.on_connect = on_connect
  49. client.on_message = on_message
  50. client.connect(target, 1883, 60)
  51.  
  52. # Blocking call that processes network traffic, dispatches callbacks and
  53. # handles reconnecting.
  54. # Other loop*() functions are available that give a threaded interface and a
  55. # manual interface.
  56. client.loop_forever()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top