I am new to the python language, but I started developing a script to manage linux servers etc ... I have a problem with a snippet of code:
def rotear():
print(" \n Disponível: \n"), os.system("ifconfig|grep eth|cut -c 1-4")
interface_internet = input(" \n Digite a Interface de Internet: ")
if interface_internet != ethers[0]:
print("Nao deu certo!")
Next, I listed the network interfaces, I mounted this snippet of code, but I wanted to figure out how to get the list of network interfaces, and make a true or false condition to proceed with the code
ex:
I've listed the interface with ifconfig | grep eth | cut -c 1-4
eth0
eth1
If interface_internet is different from one of the above listings, do this otherwise, do that
I wanted a solution on this ...
So I put the code:
def rotear():
ethers = ['eth0','eth1','eth2','wlan0','wlan1','ath0','ath1']
print(" \n Listando Interfaces de Rede(s)..."),time.sleep(1)
print(" \n Disponível: \n"), os.system("ifconfig|grep eth|cut -c 1-4")
interface_internet = input(" \n Digite a Interface de Internet: ")
for device in ethers:
if interface_internet == device:
header(" \n 1 - Habilitar Roteamento")
header(" 2 - Desabilitar Roteamento\n")
encaminhar = input(" Escolha uma Opção de Roteamento:")
if encaminhar == "1":
os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
os.system("iptables -t nat -A POSTROUTING -o %s -j MASQUERADE" % (interface_internet))
sucess(" \n Roteamento Habilitado Com Sucesso..."),tcl()
elif encaminhar == "2":
os.system("echo 0 > /proc/sys/net/ipv4/ip_forward")
sucess(" \n Roteamento Desabilitado Com Sucesso..."),tcl()
else:
fail(" \n Atenção: Valor Inválido. ")
I'm just having a problem, if I put the value: eth2 for example, it makes two loops, saying that the value is invalid until it hits ... How do I resolve this now?