python - How do you get the IP address of a given network interface? -
Is there a function to get the IP address of the given network interface in Python?
I want to get an IP address of en1.
This is the result of ifconfig on my machine.
ex> $ sudo pip Install the Netiffs $ python Python 2.6.1 (r261: 67515, June 24, 2010, 21:47:49) [GCC 4.2.1 (Built 5646 for Apple Inc.) ] Type "help", "copyright", "credit" or "license" on Darwin for more information. Import Netifes netifaces.ifaddresses ( 'N 0') {18: [{addr ': '10: 9 A: DD: 52: 89: DC "}], 2: [{' Broadcast ': '10 .188.55.255' netmask '' 255.255 .254.0 'Spir': '10 .188.55.130 '}] 30: [{' netmask '' FFF: FFF: Ffff: Ffff :: ',' addr ':' fe80 :: 12 9a: ddff : Fe52: 89dc% en0 '}] $ ifconfig lo0: flags = 8049 & lt; UP, Loopback, Running, Multicast & gt; MTU 16384 inet6 :: 1 prefixlen 128 inet6 fe80 :: 1% lo0 prefixlen 64 ScopeId 0x1 Cabinet 127.0.0.1 netmask 0xff000000 gif0: flags = 8010 & LT; POINTOPOINT, multicast & gt; Mtu 1280 stf0: Flags = 0 & lt; & Gt; MTU 1280 N: Flag = 8863 & lt; UP, Broadcast, Smart, Running, Simplex, Multicast & gt; MTU 1500 ether 00: 23: 32: Ho: 4e: 90 Media: AutoSelect Status: Inactive en1: Flags = 8863 & LT; Uttar Pradesh, Broadcast, Smart, Race, Simplex, Multicast & gt; MTU 1500 Essential 00: 23: 6C: 7e: 3E: 0C inet6 fe80 :: 223: 6cff: fe7e: 3e0c% en1 prefixlen 64 ScopeId 0x5 Cabinet 192.168.1.70 netmask 0xffffff00 broadcast 192.168.1.255 Media: AutoSelect Status: Active vmnet1: Flags = 8863 & LT; Uttar Pradesh, Broadcast, Smart, Race, Simplex, Multicast & gt; MTU 1500 Essential 00: 50: 56: c0: 00: 01 Cabinet 172.16.64.1 netmask 0xffffff00 broadcast 172.16.64.255 vmnet8: flags = 8863 & LT; Uttar Pradesh, Broadcast, Smart, Race, Simplex, Multicast & gt; MTU 1500 ether 00: 50: 56: c0: 00: 08 Cabinet 172.16.174.1 Netmask 0xffffff00 Broadcast 172.16.174.255 vboxnet0: Flags = 8842 & LT; Broadcast, running, simplex, multicast & gt; MTU 1500 ether 0A: 00: 27: 00: 00: 00
Comments
Post a Comment