-
Notifications
You must be signed in to change notification settings - Fork 10
/
init.py
58 lines (41 loc) · 1.12 KB
/
init.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
48
49
50
51
52
53
54
55
56
57
58
#! /bin/python
import requests
import os,time
# this script should be firstly running before you need ips to connect each client
host = "139.129.52.57"
url = "http://" + host + "/"
username = "root"
password = "toor"
newpassword = "pwd4ssh."
#when testing
#password = newpassword
ips = []
#compare the the modify day of given file with today
def timediff(f):
if os.path.isfile(f):
today = time.localtime().tm_mday
ftoday = time.gmtime(os.stat(f).st_mtime).tm_mday
return today != ftoday
else:
return True
def getips():
global ips
f = "today_ip_cache.txt"
ret = timediff(f)
if not ret:
ips = open(f).read().split('\n')[:-1]
else:
ipurl = url + "ip.txt"
ipl = requests.get(ipurl).content.split('\n')[:-1]
ips = set(ipl)
fp = open(f,'w')
for ip in ips:
fp.write(ip + '\n')
return ips
def init():
f = "/root/.ssh/known_hosts"
if os.path.isfile(f):
os.unlink(f)
# get iplist from local cache file or remote website server
getips()
init()