Ejemplo n.º 1
0
 def getGateway(self):
     """
     Return the gateway address of the CIDR range
     
     >>> network = Subnet('192.168.1.0/24')
     >>> network.getGateway
     '192.168.1.254'
     """
     if self.low_gateway:
         return iptools.long2ip(iptools.ip2long(self.base) + 1)
     else:
         return iptools.long2ip(iptools.ip2long(self.base) + self.num_addr - 2)
Ejemplo n.º 2
0
    def usable_addresses(self, low_reserve=5, high_reserve=5):
        """
        Returns a list of the usable IP addresses in the CIDR range
        
        >>> network = Subnet('192.168.1.0/24')
        >>> len(network.usable_addresses())
        244
        
        :param low_reserve: Reserve how many low ip addresses. Default: 5
        :type low_reserve: int
        :param high_reserve: Reserver how many high ip addreses. Default: 5
        :type high_reserve: int
        """
        first_usable = self.first_address + low_reserve
        last_usable = self.last_address - high_reserve

        if self.low_gateway:
            first_usable += 2
        else:
            last_usable -= 1

        total = last_usable - first_usable
        addresses = []
        for i in range(first_usable, last_usable, 1):
            ip = iptools.long2ip(i)
            addresses.append(ip)
        return addresses
Ejemplo n.º 3
0
 def last(self):
     """ 
     Return the last IP address in the CIDR
     
     >>> network = Subnet('192.168.1.0/24')
     >>> network.last
     '192.168.1.255'
     """
     return iptools.long2ip(self.last_address)
Ejemplo n.º 4
0
 def first(self):
     """ 
     Return the first IP address in the CIDR 
     
     >>> network = Subnet('192.168.1.0/24')
     >>> network.first
     '192.168.1.0'
     """
     return iptools.long2ip(self.first_address)
Ejemplo n.º 5
0
    def to_python(self, value):
        if value is None:
            return value

        elif isinstance(value, str) or isinstance(value, unicode):
            return value

        elif isinstance(value, int) or isinstance(value, long):
            return iptools.long2ip(value)

        assert False, "This should never happen"
Ejemplo n.º 6
0
 def getNetmask(self):
     """
     Return the netmask for the CIDR range
     
     >>> network = Subnet('192.168.1.0/24')
     >>> network.getNetmask
     '255.255.255.0'
     """
     decmask = 0
     for i in range(0,31):
         if (i < self.mask):
             decmask += 1*2**(31-i)
     return iptools.long2ip(decmask)
Ejemplo n.º 7
0
    def send_channel(self,channel):
        global hdhrs
        for hdhr in hdhrs:
            if hdhr['busy'] == False:
                hdhr['busy'] = True
                break
            hdhr = None
        if hdhr is None:
            self.send_response(503,'No HDHR avaliable')
            return
        
        print "%s:%s" % (hdhr['ip'],hdhr['tuner'])
        try:
            libhdhr = LibHdhr()
            device=libhdhr.device_create(HDHOMERUN_DEVICE_ID_WILDCARD,hdhr['ip_long'],hdhr['tuner'])

            localip=libhdhr.device_get_local_machine_addr(device)
            target='udp://%s:%d/' % ( iptools.long2ip(localip) , hdhr['local_port'])
            libhdhr.device_set_tuner_target(device,target)

            listener=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            listener.bind(('0.0.0.0',hdhr['local_port']))
            listener_fh=listener.fileno()

            self.log_message("tuning to channel %s" % channel)
            vchannel_result=libhdhr.device_set_tuner_vchannel(device,channel)
            if vchannel_result == 0:
                self.send_response(404, 'Channel not found or unable to tune')
                self.send_header("X-Tuner","%s:%s" % (hdhr['ip'],hdhr['tuner']))
                self.end_headers()
                return
            self.send_response(200,'OK')
            vstatus = get_vstatus_packed(libhdhr,device)
            self.log_message(vstatus)
            self.send_header("X-V-Status",vstatus)
            self.send_header("X-Tuner","%s:%s" % (hdhr['ip'],hdhr['tuner']))
            self.send_header("X-Local-Port",hdhr['local_port'])
            self.send_header("Content-type","video/mp2t")
            self.end_headers()
            while True:
                data = listener.recvfrom(2048)
                self.wfile.write(data[0])
        finally:
            hdhr['busy'] = False
Ejemplo n.º 8
0
    def createFromPrivateMessage(self, PrivateMessage):
        self.PrivateMessage = PrivateMessage
        privmsg = PrivateMessage.privmsg
        if ("DCC CHAT CHAT" != privmsg[0:13]):
            raise Exception("Invalid argument")

        # 2130706433 47372
        ipEnd = privmsg.find(" ", 14)
        self.longIp = int(privmsg[14:ipEnd])
        self.ip = iptools.long2ip(self.longIp)
        self.port = int(privmsg[ipEnd + 1:])
        print "parsed longIp(%d) ip(%s) port(%d)" % (self.longIp, self.ip,
                                                     self.port)

        self.nick = PrivateMessage.ParsedMessage.Netmask.nick
        self.ident = PrivateMessage.ParsedMessage.Netmask.ident
        self.host = PrivateMessage.ParsedMessage.Netmask.host
        print "dcc chat nick(%s) ident(%s) host(%s)" % (self.nick, self.ident,
                                                        self.host)
Ejemplo n.º 9
0
hdhr_tuner = 1
udp_relay_listen_port = 1236


libhdhr = LibHdhr()

device = libhdhr.device_create(HDHOMERUN_DEVICE_ID_WILDCARD, iptools.ip2long(hdhr_ip), hdhr_tuner)

listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
listener.bind(('0.0.0.0', udp_relay_listen_port))
#listener.setblocking(False)
#listener_fh=listener.fileno()


localip = libhdhr.device_get_local_machine_addr(device)
target = 'udp://%s:%d/' % (iptools.long2ip(localip), udp_relay_listen_port)
libhdhr.device_set_tuner_target(device, target)

dir_timestamp = time.strftime("%Y-%m-%d %H:%M:%S %Z")
os.mkdir('/www/hdhr.adam.gs/scanner/%s' % dir_timestamp)

req = urllib2.Request(
    url='http://hdhr.adam.gs/lineup.xml'
)
fh = urllib2.urlopen(req)
data = fh.read()
xdata = ET.fromstring(data)
programs = xdata.findall("Program")


want_channels = sys.argv[1:]
Ejemplo n.º 10
0
hdhr_ip = '10.0.8.215'
hdhr_tuner = 1
udp_relay_listen_port = 1236

libhdhr = LibHdhr()

device = libhdhr.device_create(HDHOMERUN_DEVICE_ID_WILDCARD,
                               iptools.ip2long(hdhr_ip), hdhr_tuner)

listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
listener.bind(('0.0.0.0', udp_relay_listen_port))
#listener.setblocking(False)
#listener_fh=listener.fileno()

localip = libhdhr.device_get_local_machine_addr(device)
target = 'udp://%s:%d/' % (iptools.long2ip(localip), udp_relay_listen_port)
libhdhr.device_set_tuner_target(device, target)

dir_timestamp = time.strftime("%Y-%m-%d %H:%M:%S %Z")
os.mkdir('/www/hdhr.adam.gs/scanner/%s' % dir_timestamp)

req = urllib2.Request(url='http://hdhr.adam.gs/lineup.xml')
fh = urllib2.urlopen(req)
data = fh.read()
xdata = ET.fromstring(data)
programs = xdata.findall("Program")

want_channels = sys.argv[1:]

for program in programs:
    channel = program.find("GuideNumber").text
Ejemplo n.º 11
0
        copy_protected = True
    else:
        copy_protected = False

    print("vstatus:")
    print("        vchannel         %s" % (vstatus[2].vchannel))
    print("        name             %s" % (vstatus[2].name))
    print("        auth             %s" % (vstatus[2].auth))
    print("        cci              %s" % (vstatus[2].cci))
    print("        cgms             %s" % (vstatus[2].cgms))
    print("        subscribed       %s" % (subscribed))
    print("        available        %s" % (available))
    print("        copy_protected   %s" % (copy_protected))


libhdhr = LibHdhr()

device = libhdhr.device_create(HDHOMERUN_DEVICE_ID_WILDCARD,
                               iptools.ip2long('10.0.8.211'), 0)

print iptools.long2ip(libhdhr.device_get_local_machine_addr(device))

pp_vstatus(libhdhr, device)
libhdhr.device_set_tuner_vchannel(device, '802')
time.sleep(1)
pp_vstatus(libhdhr, device)

libhdhr.device_set_tuner_vchannel(device, '1216')
time.sleep(1)
pp_vstatus(libhdhr, device)
Ejemplo n.º 12
0
def long2ip(value):
    """Converts a long value to dotted IP address String"""
    return iptools.long2ip(value)
Ejemplo n.º 13
0
from zcode_dict import *

isp_err = open("err/check-google_err", "w+");

while True:
    #print prov_map
    lines = sys.stdin.readlines(300000)
    if not lines: break
    for line in lines:
        line = line.strip()
        if '' == line: continue
        rec = line.split('`')       
        if len(rec)<4:
            continue
        (intip_beg,intip_end,prov,city) = rec
        ip_begstr = iptools.long2ip(long(intip_beg))
        ip_endstr = iptools.long2ip(long(intip_end))
        if prov != "" and city == "":
            if prov in prov_map:
                prov = prov_map[prov]
            else:
                print >>isp_err, "prov`%s" %(prov)
        elif prov != "" and city != "":
	    if prov in ["北京市","天津市","上海市","重庆市"]:
		    city = ''  
            key = prov + "," + city
            if key in prov_city_map:
                (prov, city) = prov_city_map[key].split(",")
            else:
                print >>isp_err, "prov_city`%s`%s" %(prov,city)
        elif prov == "" and city != "":
Ejemplo n.º 14
0
    if vstatus[2].copy_protected == 1:
        copy_protected = True
    else:
        copy_protected = False

    print ("vstatus:")
    print ("        vchannel         %s" % (vstatus[2].vchannel))
    print ("        name             %s" % (vstatus[2].name))
    print ("        auth             %s" % (vstatus[2].auth))
    print ("        cci              %s" % (vstatus[2].cci))
    print ("        cgms             %s" % (vstatus[2].cgms))
    print ("        subscribed       %s" % (subscribed))
    print ("        available        %s" % (available))
    print ("        copy_protected   %s" % (copy_protected))


libhdhr = LibHdhr()

device = libhdhr.device_create(HDHOMERUN_DEVICE_ID_WILDCARD, iptools.ip2long("10.0.8.211"), 0)

print iptools.long2ip(libhdhr.device_get_local_machine_addr(device))

pp_vstatus(libhdhr, device)
libhdhr.device_set_tuner_vchannel(device, "802")
time.sleep(1)
pp_vstatus(libhdhr, device)

libhdhr.device_set_tuner_vchannel(device, "1216")
time.sleep(1)
pp_vstatus(libhdhr, device)