Jan-25-2018, 09:46 AM
I got a task at where I am learning python to write a code that let me see ip of lo eth and nettwork card.
Then i got tast to print out both the ethernet and the nettwork card at same time.
I stuck there since still pretty new to python and don't know how to do it and been trying to find out for few days with no luck. Any suggestion?
#!/usr/bin/env python
def finn_ip():
import netifaces
netti = netifaces.interfaces()
for i in netti:
print i
p = raw_input('skriv inn her: ')
ia = netifaces.ifaddresses(p)
if 2 in ia.keys():
return ia[2][0]['addr']
else:
return False
ip = finn_ip()
if ip is False:
print 'No IP found'
else:
print ip
Then i got tast to print out both the ethernet and the nettwork card at same time.
I stuck there since still pretty new to python and don't know how to do it and been trying to find out for few days with no luck. Any suggestion?
#!/usr/bin/env python
def finn_ip():
import netifaces
netti = netifaces.interfaces()
for i in netti:
print i
p = raw_input('skriv inn her: ')
ia = netifaces.ifaddresses(p)
if 2 in ia.keys():
return ia[2][0]['addr']
else:
return False
ip = finn_ip()
if ip is False:
print 'No IP found'
else:
print ip