|
4 | 4 | import re |
5 | 5 | from prettytable import PrettyTable |
6 | 6 |
|
| 7 | +import os |
| 8 | +import sys |
| 9 | +import subprocess |
| 10 | + |
| 11 | +global platform |
| 12 | +if "linux" in sys.platform: |
| 13 | + from crontab import CronTab |
| 14 | + platform = "linux" |
| 15 | +elif "win" in sys.platform: |
| 16 | + platform = "win" |
| 17 | + |
7 | 18 | def run_core(domain, area): |
8 | 19 | # Encrypt! |
9 | | - if area == "debug": |
10 | | - iplist = ['220.181.38.148', '39.156.69.79', '210.23.129.34', '210.23.129.34', '220.181.38.148', '39.156.69.79', '202.108.22.220', '220.181.33.31', '112.80.248.64', '14.215.178.80', '180.76.76.92', '210.23.129.34', '210.23.129.34', '39.156.69.79', '220.181.38.148', '203.12.160.35', '203.12.160.35', '39.156.69.79', '220.181.38.148', |
11 | | - '202.108.22.220', '220.181.33.31', '112.80.248.64', '14.215.178.80', '180.76.76.92', '203.12.160.35', '203.12.160.35', '220.181.38.148', '39.156.69.79', '61.8.0.113', '61.8.0.113', '220.181.38.148', '39.156.69.79', '202.108.22.220', '220.181.33.31', '112.80.248.64', '14.215.178.80', '180.76.76.92', '61.8.0.113', '61.8.0.113'] |
12 | | - else: |
13 | | - ipdict = multi.multi_local_dns(domain) |
14 | | - print("[+]Got domain! \n" + str(list(ipdict[1].keys()))) |
| 20 | + print("[+]platform detect: "+platform) |
| 21 | + ipdict = multi.multi_local_dns(domain,platform) |
| 22 | + print("[+]Got domain! \n" + str(list(ipdict[1].keys()))) |
15 | 23 | return domain, ipdict |
16 | 24 |
|
17 | 25 |
|
@@ -47,6 +55,36 @@ def output_dic(domain, ip_dic): |
47 | 55 |
|
48 | 56 | print(table) |
49 | 57 |
|
| 58 | +def update_hosts(domain, new_ip): |
| 59 | + if os.getuid() != 0: |
| 60 | + sys.exit("not root?") |
| 61 | + |
| 62 | + if len(new_ip) != 0: |
| 63 | + print("[-]Start updating hosts") |
| 64 | + for ip in new_ip[::-1]: |
| 65 | + cmd = ['sed', '-i', rf'/^[0-9.]\+[[:space:]]\+{domain}\>/s/[^[:space:]]\+/{ip}/', '/etc/hosts'] |
| 66 | + try: |
| 67 | + subprocess.check_call(cmd) |
| 68 | + print("Add {0} {1}".format(domain, ip)) |
| 69 | + except: |
| 70 | + print("Error: {0} {1}".format(domain, ip)) |
| 71 | + print("[+]Done!") |
| 72 | + |
| 73 | +def update_crontab(domain): |
| 74 | + my_user_cron = CronTab(user=True) # 创建当前用户的crontab |
| 75 | + # 删除原有的crontab文件中重复的内容 |
| 76 | + |
| 77 | + objs = my_user_cron.find_comment(domain) |
| 78 | + if objs: |
| 79 | + for obj in objs: |
| 80 | + my_user_cron.remove(obj) |
| 81 | + |
| 82 | + job = my_user_cron.new(command='python3 /program/python/Hosts-chooser-master main.py -t ' + domain + ' --clean') |
| 83 | + job.setall('*/2 * * * *') # 设置执行时间 |
| 84 | + job.set_comment(domain) |
| 85 | + |
| 86 | + my_user_cron.write() |
| 87 | + |
50 | 88 | class domainError(Exception): |
51 | 89 | def __init__(self,err='invalid domian'): |
52 | 90 | Exception.__init__(self,err) |
0 commit comments