-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
72 lines (61 loc) · 1.94 KB
/
tools.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import uuid
import subprocess
import configparser
import socket
import shutil
config = configparser.ConfigParser()
def rmmod():
os.system("sync")
os.system("rmmod g_mass_storage")
os.system("sync")
def insmod(fdisk):
os.system("sync")
out_bytes = subprocess.check_output(['uname','-r']).decode('utf-8').replace("\n","")
os.system("insmod /lib/modules/{}/kernel/drivers/usb/gadget/legacy/g_mass_storage.ko file={} stall=0 removable=1".format(out_bytes,fdisk))
os.system("sync")
def get_mac():
mac_address = uuid.UUID(int=uuid.getnode()).hex[-12:].upper()
mac_address = '-'.join([mac_address[i:i+2] for i in range(0, 11, 2)])
return mac_address
def umount(disk):
os.system("sync")
os.system("umount {}".format(disk))
os.system("sync")
def mount(disk,path):
os.system("sync")
os.system("mount {} {}".format(disk,path))
os.system("sync")
def get_config(file):
config.read(file)
list = dict()
for i in config.sections():
s = dict()
for j in config.items(i):
s[j[0]] = j[1]
list[i] = s
return list
def set_ip(d):
if(d["ip"])=="0.0.0.0":
text = "auto eth0\niface eth0 inet dhcp\n"
with open("/etc/network/interfaces.d/usereth0","w",encoding="utf-8") as f:
f.writelines(text)
else:
text = "auto eth0\niface eth0 inet static\naddress {}\nnetmask {}\ngateway {}\ndns-nameservers {}\n".format(d["ip"],d["netmask"],d["gateway"],d["dns"])
with open("/etc/network/interfaces.d/usereth0","w",encoding="utf-8") as f:
f.writelines(text)
def get_ip():
ip = "127.0.0.1"
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
def log_move(src,dst):
os.sync()
for i in os.listdir(src):
path = os.path.join(src,i)
shutil.copy(path,dst)
os.sync()