-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.py
executable file
·29 lines (23 loc) · 907 Bytes
/
static.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
#!/usr/bin/env python
import subprocess
intr = raw_input("Interface:\n> ")
addr = raw_input("IP Address:\n> ")
mask = raw_input("Subnet Mask:\n> ")
gate = raw_input("Default Gateway (optional):\n> ")
dns = raw_input("DNS Server (optional):\n> ")
subprocess.call(["sudo", "cp", "/etc/resolv.conf", "/tmp/resolv.conf.backup"])
if intr == "en0":
subprocess.call(["sudo", "networksetup", "-setmanual", "ethernet", addr, mask, gate])
elif intr == "en1":
subprocess.call(["sudo", "networksetup", "-setmanual", "Wi-Fi", addr, mask, gate])
else:
print "no valid interface specified (en0 or en1)"
quit()
if len(dns) != 0:
if intr=="en0":
subprocess.call(["sudo", "networksetup", "-setdnsservers", "ethernet", dns])
elif intr=="en1":
subprocess.call(["sudo", "networksetup", "-setdnsservers", "Wi-FI", dns])
else:
subprocess.call(["sudo", "mv", "/tmp/resolv.conf.backup", "/etc/resolv.conf"])
quit()