From 59d55593db83769da5b51a58d65c631544699c10 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Thu, 5 Sep 2013 15:22:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B8=D0=BD=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D0=B5=D1=82=D0=B5=D0=B2=D0=BE=D0=B9=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calculate/lib/utils/ip.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/calculate/lib/utils/ip.py b/calculate/lib/utils/ip.py index 669c490..8ac17e6 100644 --- a/calculate/lib/utils/ip.py +++ b/calculate/lib/utils/ip.py @@ -41,6 +41,9 @@ SIOCGIFADDR = 0x8915 SIOCGIFNETMASK = 0x891B SIOCGIFHWADDR = 0x8927 +# Resources allocated +IFF_RUNNING = 0x40 + # ip digit from 0|1-255|254 (template) IP_DIG = "[%s-9]|(?:1[0-9]|[1-9])[0-9]|2[0-4][0-9]|25[0-%s]" # ip net 0-32 @@ -195,6 +198,17 @@ def getIp(iface): ip = struct.unpack('16sH2x4s8x', res)[2] return socket.inet_ntoa(ip) +def getPlugged(iface): + sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + ifreq = struct.pack('16sH14s', iface, socket.AF_INET, '\x00'*14) + try: + res = fcntl.ioctl(sockfd, SIOCGIFFLAGS, ifreq) + except IOError: + return False + finally: + sockfd.close() + return bool(struct.unpack('16sH2x4s8x', res)[1] & IFF_RUNNING) + def getMask(iface): """ Get mask for interface