getting all network interface in linux machine using python

Script python ini saya buat untuk mendapatkan semua antarmuka jaringan pada mesin linux, silakan dicoba semoga bermaanfaat… 🙂

#!/usr/bin/python
# <l0g.bima@gmail.com>
# getting all network interface in linux machine

iface=[] # membuat list kosong

def network_card():
	for line in open('/proc/net/dev'): # buka file device
		dev=line.split()[0].split(':')[0] # menjadikan list kemudian buang spasi & tanda titik dua
		iface.append(dev) # menambahkan interface yang di dapat
        # hapus 2 list pertama
	iface.pop(0)
	iface.pop(0)
	return iface
			
iface=network_card()
print 'Network interface: %s' %(iface)
Advertisements
This entry was posted in python. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s