コード例 #1
0
ファイル: dnsproxy.py プロジェクト: 11liju/SimpleDNS
    def parseDispatchConfig(self, config):
        """
        Parse dispatch config file for 'Address' and 'Server' rules
        """
        if not os.path.exists(config):
            return
        f = open(config, 'r')
        for l in f.readlines():
            l = l.strip()
            if l == "" or l.startswith('#'):
                continue
            t = l.split('=')
            _type = t[0]
            _map = t[1]
            if _type == 'server':
                _entry = _map.split('/')
                _path = _entry[1].strip()
                _addr_and_port = _entry[2].strip().split('#')
                _addr = _addr_and_port[0]
                if not is_address_validate(_addr):
                    continue
                _port = "53"
                if len(_addr_and_port) == 2:
                    _port = _addr_and_port[1]

                _port = int(_port)
                self.serverMap[_path] = (_addr, _port)

            if _type == 'address':
                _entry = _map.split('/')
                _path = _entry[1].strip()
                _addr = _entry[2].strip()
                if not is_address_validate(_addr):
                    continue
                self.addressMap[_path] = _addr
コード例 #2
0
    def parseDispatchConfig(self, config):
        """
        Parse dispatch config file for 'Address' and 'Server' rules
        """
        if not os.path.exists(config):
            return
        f = open(config, 'r')
        for l in f.readlines():
            l = l.strip()
            if l == "" or l.startswith('#'):
                continue
            t = l.split('=')
            _type = t[0]
            _map = t[1]
            if _type == 'server':
                _entry = _map.split('/')
                _path = _entry[1].strip()
                _addr_and_port = _entry[2].strip().split('#')
                _addr = _addr_and_port[0]
                if not is_address_validate(_addr):
                    continue
                _port = "53"
                if len(_addr_and_port) == 2:
                    _port = _addr_and_port[1]

                _port = int(_port)
                self.serverMap[_path] = (_addr, _port)

            if _type == 'address':
                _entry = _map.split('/')
                _path = _entry[1].strip()
                _addr = _entry[2].strip()
                if not is_address_validate(_addr):
                    continue
                self.addressMap[_path] = _addr
コード例 #3
0
def test_is_address_validate_with_incorrect_ipv6_address():
    addr = "sdff>?>"
    r = is_address_validate(addr)
    assert r == False
コード例 #4
0
def test_is_address_validate_with_correct_ipv6_address():
    addr = "fe80::1"
    r = is_address_validate(addr)
    assert r == True
コード例 #5
0
def test_is_address_validate_with_incorrect_ipv4_address():
    addr = "1.1.1."
    r = is_address_validate(addr)
    assert r == False
コード例 #6
0
def test_is_address_validate_with_correct_ipv4_address():
    addr = "1.1.1.1"
    r = is_address_validate(addr)
    assert r == True