示例#1
0
def test_ss_tulpn_get_port():
    ss = SsTULPN(context_wrap(Ss_TULPN))
    exp01 = [{
        'Netid': 'tcp',
        'Process': 'users:(("sshd",pid=1416,fd=4))',
        'Peer-Address-Port': ':::*',
        'Send-Q': '128',
        'Local-Address-Port': ':::2223',
        'State': 'LISTEN',
        'Recv-Q': '0'
    }]
    assert ss.get_localport("2223") == exp01
    exp02 = [{
        'Netid': 'udp',
        'Process': 'users:(("rpc.statd",pid=29559,fd=10))',
        'Peer-Address-Port': ':::12345',
        'Send-Q': '0',
        'Local-Address-Port': ':::37968',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert ss.get_peerport("12345") == exp02
    assert ss.get_port("12345") == exp02
    exp03 = [{
        'Netid': 'tcp',
        'Process': 'users:(("sshd",1231,3))',
        'Peer-Address-Port': '*:*',
        'Send-Q': '128',
        'Local-Address-Port': '*:22',
        'State': 'LISTEN',
        'Recv-Q': '0'
    }]
    assert ss.get_localport("22") == exp03
    assert ss.get_peerport("22") == []
    assert ss.get_port("22") == exp03
示例#2
0
def test_ss_tupnla_get_port():
    # Added test cases for testing two parser for one spec.
    # Used data from spec ss -tulpn and run parser SsTULPN(ss -tulpn)
    ssl = SsTULPN(context_wrap(SS_TULPN_2))
    exp02 = [{
        'Netid': 'udp',
        'Peer-Address-Port': '0.0.0.0:*',
        'Send-Q': '0',
        'Local-Address-Port': '0.0.0.0:34453',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert len(ssl.data) == 22
    assert ssl.get_localport("34453") == exp02

    # Used data from spec ss -tupna and run parser SsTULPN(ss -tulpn)
    ssl = SsTULPN(context_wrap(SS_TUPNA_2))
    exp02 = [{
        'Netid': 'udp',
        'Peer-Address-Port': '0.0.0.0:*',
        'Send-Q': '0',
        'Local-Address-Port': '0.0.0.0:34453',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert len(ssl.data) == 22
    assert ssl.get_localport("34453") == exp02

    # Used data from spec ss -tupna and run parser SsTUPNA(ss -tupna)
    ssl = SsTUPNA(context_wrap(SS_TUPNA_2))
    exp02 = [{
        'Netid': 'udp',
        'Peer-Address-Port': '0.0.0.0:*',
        'Send-Q': '0',
        'Local-Address-Port': '0.0.0.0:34453',
        'State': 'UNCONN',
        'Recv-Q': '0'
    }]
    assert len(ssl.data) == 33
    assert ssl.get_localport("34453") == exp02