-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailscale_api.py
47 lines (31 loc) · 1.13 KB
/
tailscale_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import requests
from requests.auth import HTTPBasicAuth
from datetime import *
def api_call():
x = 0
# Provide your tailnet ID and api_key
tailnet="yalindogusahin.github"
api_key="tskey-api-kDAtcr6CNTRL-AHCbaiVopp7WXNTGzixSr7XAkCXRST3P"
url = ('https://api.tailscale.com/api/v2/tailnet/{}/devices'.format(tailnet))
response = requests.get(url, auth=HTTPBasicAuth(api_key,''))
data = json.loads(response.text)
data = data['devices']
ip_addresses = []
hostnames = []
last_seen = []
device = []
y = []
for i in data:
if(data[x]['os'] == 'linux'):
# Gets IP addresses as list
ip_addresses.append(data[x]['addresses'][0])
# Gets Hostnames as list
hostnames.append(data[x]['hostname'])
last_seen.append(data[x]['lastSeen'])
device = list(zip(hostnames,ip_addresses))
x = x+1
# Last seen converted to date time format
for i in last_seen:
y.append(datetime.strptime(i,"%Y-%m-%dT%H:%M:%SZ"))
return device