示例#1
0
    def getPrefixList(gfwDir):
        """Returns list of ipaddress.IPv4Network"""

        # get GFWed network list
        nets = []
        for fn in os.listdir(gfwDir):
            fullfn = os.path.join(gfwDir, fn)
            with open(fullfn) as f:
                lineList = f.read().split("\n")
                for i in range(0, len(lineList)):
                    line = CgfwUtil.getLineWithoutBlankAndComment(lineList[i])
                    if line is None:
                        continue
                    nets.append(ipaddress.IPv4Network(line))

        # optimize network list
        nets.sort()
        i = 0
        while i < len(nets):
            j = i + 1
            while j < len(nets):
                if nets[i].overlaps(nets[j]):
                    # big network is in front of small network, so we remove small network.
                    # I think network can only "wholly contain" each other, does "partly contain" really exist?
                    del nets[j]
                    continue
                j += 1
            i += 1

        return nets
示例#2
0
    def getPrefixList(gfwDir):
        """Returns list of ipaddress.IPv4Network"""

        # get GFWed network list
        nets = []
        for fn in os.listdir(gfwDir):
            fullfn = os.path.join(gfwDir, fn)
            with open(fullfn) as f:
                lineList = f.read().split("\n")
                for i in range(0, len(lineList)):
                    line = CgfwUtil.getLineWithoutBlankAndComment(lineList[i])
                    if line is None:
                        continue
                    nets.append(ipaddress.IPv4Network(line))

        # optimize network list
        nets.sort()
        i = 0
        while i < len(nets):
            j = i + 1
            while j < len(nets):
                if nets[i].overlaps(nets[j]):
                    # big network is in front of small network, so we remove small network.
                    # I think network can only "wholly contain" each other, does "partly contain" really exist?
                    del nets[j]
                    continue
                j += 1
            i += 1

        return nets
示例#3
0
 def getDomainList(gfwDomainDir):
     # get GFWed domain list
     ret = []
     for fn in os.listdir(gfwDomainDir):
         fullfn = os.path.join(gfwDomainDir, fn)
         with open(fullfn) as f:
             lineList = f.read().split("\n")
             for i in range(0, len(lineList)):
                 line = CgfwUtil.getLineWithoutBlankAndComment(lineList[i])
                 if line is None:
                     continue
                 ret.append(line)
     return ret
示例#4
0
 def getDomainList(gfwDomainDir):
     # get GFWed domain list
     ret = []
     for fn in os.listdir(gfwDomainDir):
         fullfn = os.path.join(gfwDomainDir, fn)
         with open(fullfn) as f:
             lineList = f.read().split("\n")
             for i in range(0, len(lineList)):
                 line = CgfwUtil.getLineWithoutBlankAndComment(lineList[i])
                 if line is None:
                     continue
                 ret.append(line)
     return ret