Пример #1
0
 def get_ip(self):
     if self.last_got_ip + EXPIRE_CACHE < clock():
         local_ips = IP_List()
         local_ips.set_intranet_addresses()
         try:
             for info in socket.getaddrinfo(socket.gethostname(),0,socket.AF_INET):
                         # exception if socket library isn't recent
                 self.local_ip = info[4][0]
                 if local_ips.includes(self.local_ip):
                     self.last_got_ip = clock()
                     if DEBUG:
                         print 'Local IP found: '+self.local_ip
                     break
             else:
                 raise ValueError('couldn\'t find intranet IP')
         except:
             self.local_ip = None
             if DEBUG:
                 print 'Error finding local IP'
                 print_exc()
     return self.local_ip
Пример #2
0
 def get_ip(self):
     if self.last_got_ip + EXPIRE_CACHE < clock():
         local_ips = IP_List()
         local_ips.set_intranet_addresses()
         try:
             for info in socket.getaddrinfo(socket.gethostname(),0,socket.AF_INET):
                         # exception if socket library isn't recent
                 self.local_ip = info[4][0]
                 if local_ips.includes(self.local_ip):
                     self.last_got_ip = clock()
                     if DEBUG:
                         print 'Local IP found: '+self.local_ip
                     break
             else:
                 raise ValueError('couldn\'t find intranet IP')
         except:
             self.local_ip = None
             if DEBUG:
                 print 'Error finding local IP'
                 print_exc()
     return self.local_ip
Пример #3
0
    def get_ip(self):
        if self.last_got_ip + EXPIRE_CACHE < clock():
            if self.local_ip is None:
                local_ips = IP_List()
                local_ips.set_intranet_addresses()
                try:
                    for info in socket.getaddrinfo(socket.gethostname(), 0, socket.AF_INET):
                        self.local_ip = info[4][0]
                        if local_ips.includes(self.local_ip):
                            self.last_got_ip = clock()
                            if DEBUG:
                                print >> sys.stderr, 'upnpX: Local IP found: ' + self.local_ip
                            break
                    else:
                        raise ValueError("upnpX: couldn't find intranet IP")

                except:
                    self.local_ip = None
                    if DEBUG:
                        print >> sys.stderr, 'upnpX: Error finding local IP'
                        print_exc()

        return self.local_ip
Пример #4
0
    def get_ip(self):
        if self.last_got_ip + EXPIRE_CACHE < clock():
            if self.local_ip is None:
                local_ips = IP_List()
                local_ips.set_intranet_addresses()
                try:
                    for info in socket.getaddrinfo(socket.gethostname(), 0,
                                                   socket.AF_INET):
                        self.local_ip = info[4][0]
                        if local_ips.includes(self.local_ip):
                            self.last_got_ip = clock()
                            if DEBUG:
                                print >> sys.stderr, 'upnpX: Local IP found: ' + self.local_ip
                            break
                    else:
                        raise ValueError("upnpX: couldn't find intranet IP")

                except:
                    self.local_ip = None
                    if DEBUG:
                        print >> sys.stderr, 'upnpX: Error finding local IP'
                        print_exc()

        return self.local_ip