-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·77 lines (62 loc) · 2.84 KB
/
install
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
73
74
75
76
77
#!/usr/bin/python3
import subprocess as sub
import sys
from konzola import Color
import konzola
def setDhcpIface(configDict):
with open("/etc/default/isc-dhcp-server","w") as f:
f.write(f'INTERFACESv4={configDict["iface"]}')
def install():
print(f"""{Color.YELLOW}Installing dependencies root privilages will be needed
Packages to install are: hostapd, iptables-persistent, isc-dhcp-server{Color.RESET}""")
try:
sub.check_output("sudo apt install hostapd iptables-persistent isc-dhcp-server", shell=True)
except Exception as e:
print(f"{Color.RED}{e}{Color.RESET}")
sys.exit("Failed to Install dependencies")
iface = str(input("Enter wlan interface eg. wlan0: "))
defaultConf={"iface": iface,
"ip": "192.168.42.1",
"mask": "255.255.255.0",
"subnet": "192.168.42.0",
"broadcast":"192.168.42.255",
"dns1": "8.8.8.8",
"dns2": "8.8.4.4",
"ssid": "MiniRouterByKikin",
"passphrase": "1am53CR3T",
"channel": "1"}
print(f"{Color.YELLOW}Creating dhcp configuration{Color.RESET}")
konzola.dhcpWrite(defaultConf)
print(f"{Color.YELLOW}Setting dhcp interface{Color.RESET}")
setDhcpIface(defaultConf)
print(f"{Color.YELLOW}Setting static IP address{Color.RESET}")
konzola.saveIfaceConf(defaultConf)
print(f"{Color.YELLOW}Configuring hostapd{Color.RESET}")
konzola.hostapdWrite(defaultConf)
print(f"{Color.YELLOW}Propagate config hostapd{Color.RESET}")
with open("/etc/default/hostapd","r+") as f:
lines = f.readlines()
for line in lines:
if line == '#DAEMON_CONF=""':
line = 'DAEMON_CONF="/etc/hostapd/hostapd.conf"'
break;
with open("/etc/init.d/hostapd", "r+") as f:
lines = f.readlines()
for line in lines:
if line == "DAEMON_CONF=":
line = "DAEMON_CONF=/etc/hostapd/hostapd.conf"
break;
print(f"{Color.YELLOW}Setting ipv4 forwarding...{Color.RESET}")
with open("/etc/sysctl.conf", "a") as f:
f.write("net.ipv4.ip_forward=1")
sub.call('sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"', shell=True)
eth = str(input("Enter eth interface: "))
print(f"{Color.YELLOW}Configuring iptables{Color.RESET}")
sub.call(f"sudo iptables -t nat -A POSTROUTING -o {eth} -j MASQUERADE", shell=True)
sub.call(f"sudo iptables -A FORWARD -i {eth} -o {defaultConf['iface']} -m state --state RELATED,ESTABLISHED -j ACCEPT", shell=True)
sub.call(f"sudo iptables -A FORWARD -i {defaultConf['iface']} -o {eth} -j ACCEPT", shell=True)
sub.call("sudo iptables -t nat -S", shell=True)
sub.call("sudo iptables -S", shell=True)
sub.call('sudo sh -c "iptables-save > /etc/iptables/rules.v4"', shell=True)
if __name__=="__main__":
install()