Ejemplo n.º 1
0
    def test_get_raw__tcp(self):
        p = Packet()
        p.include(TCP(srcport=123, dstport=321, flags='psh'))

        assert ("\x00\x7b\x01\x41\x00\x00\x00\x00"
                "\x00\x00\x00\x01\x50\x08\x02\x00"
                "\xae\x1d\x00\x00") == p.get_raw()
Ejemplo n.º 2
0
    def test_get_raw__ip(self):
        p = Packet()
        p.include(
            IP(src="127.0.0.1", dst="127.0.0.1", _id=1000, _checksum=0x7900))

        if sys.platform.find('linux') != -1:
            ttl = _consts.TTL_LINUX
        elif sys.platform.find('darwin') != -1:
            ttl = _consts.TTL_MACOS
        elif sys.platform.find('win') != -1:
            ttl = _consts.TTL_WINDOWS
        elif sys.platform.find('freebsd') != -1:
            ttl = _consts.TTL_FREEBSD
        elif sys.platform.find('os2') != -1:
            ttl = _consts.TTL_OS2
        elif sys.platform.find('sunos') != -1:
            ttl = _consts.TTL_SUNOS
        elif sys.platform.find('aix') != -1:
            ttl = _consts.TTL_AIX
        elif sys.platform.find('irix') != -1:
            ttl = _consts.TTL_IRIX
        elif sys.platform.find('solaris') != -1:
            ttl = _consts.TTL_SOLARIS
        elif sys.platform.find('ultrix') != -1:
            ttl = _consts.TTL_ULTRIX
        elif sys.platform.find('dec') != -1:
            ttl = _consts.TTL_DEC
        else:
            ttl = _consts.TTL_LINUX

        expected = ("\x45\x00\x00\x14\x03\xe8\x00\x00"
                    "%c\x00\x79\x00\x7f\x00\x00\x01"
                    "\x7f\x00\x00\x01") % chr(ttl)
        assert expected == p.get_raw()
Ejemplo n.º 3
0
    def test_get_raw__tcp(self):
        p = Packet()
        p.include(TCP(srcport=123,dstport=321,flags='psh'))

        assert ("\x00\x7b\x01\x41\x00\x00\x00\x00"
                "\x00\x00\x00\x01\x50\x08\x02\x00"
                "\xae\x1d\x00\x00") == p.get_raw()
Ejemplo n.º 4
0
    def test_protos_order(self):
        order = (IP, UDP, Payload)

        p = Packet(*[x() for x in order])
        for i in xrange(len(order)):
            assert isinstance(p.protos[i], order[i])

        p = Packet(IP())
        p.include(UDP(), Payload())
        for i in xrange(len(order)):
            assert isinstance(p.protos[i], order[i])
Ejemplo n.º 5
0
    def test_protos_order(self):
        order = (IP, UDP, Payload)

        p = Packet(*[x() for x in order])
        for i in xrange(len(order)):
            assert isinstance(p.protos[i], order[i])

        p = Packet(IP())
        p.include(UDP(), Payload())
        for i in xrange(len(order)):
            assert isinstance(p.protos[i], order[i])
Ejemplo n.º 6
0
    def test_get_raw__ip(self):
        p = Packet()
        p.include(IP(src="127.0.0.1",
                    dst="127.0.0.1",
                    _id=1000,
                    _checksum=0x7900))

        if sys.platform.find('linux') != -1:
            ttl = _consts.TTL_LINUX
        elif sys.platform.find('darwin') != -1:
            ttl = _consts.TTL_MACOS
        elif sys.platform.find('win') != -1:
            ttl = _consts.TTL_WINDOWS
        elif sys.platform.find('freebsd') != -1:
            ttl = _consts.TTL_FREEBSD
        elif sys.platform.find('os2') != -1:
            ttl = _consts.TTL_OS2
        elif sys.platform.find('sunos') != -1:
            ttl = _consts.TTL_SUNOS
        elif sys.platform.find('aix') != -1:
            ttl = _consts.TTL_AIX
        elif sys.platform.find('irix') != -1:
            ttl = _consts.TTL_IRIX
        elif sys.platform.find('solaris') != -1:
            ttl = _consts.TTL_SOLARIS
        elif sys.platform.find('ultrix') != -1:
            ttl = _consts.TTL_ULTRIX
        elif sys.platform.find('dec') != -1:
            ttl = _consts.TTL_DEC
        else:
            ttl = _consts.TTL_LINUX

        expected = ("\x45\x00\x00\x14\x03\xe8\x00\x00"
                    "%c\x00\x79\x00\x7f\x00\x00\x01"
                    "\x7f\x00\x00\x01") % chr(ttl)
        assert expected == p.get_raw()
Ejemplo n.º 7
0
    def test_get_raw(self):
        if sys.platform.find('linux') != -1:
            ttl = _consts.TTL_LINUX
        elif sys.platform.find('darwin') != -1:
            ttl = _consts.TTL_MACOS
        elif sys.platform.find('win') != -1:
            ttl = _consts.TTL_WINDOWS
        elif sys.platform.find('freebsd') != -1:
            ttl = _consts.TTL_FREEBSD
        elif sys.platform.find('os2') != -1:
            ttl = _consts.TTL_OS2
        elif sys.platform.find('sunos') != -1:
            ttl = _consts.TTL_SUNOS
        elif sys.platform.find('aix') != -1:
            ttl = _consts.TTL_AIX
        elif sys.platform.find('irix') != -1:
            ttl = _consts.TTL_IRIX
        elif sys.platform.find('solaris') != -1:
            ttl = _consts.TTL_SOLARIS
        elif sys.platform.find('ultrix') != -1:
            ttl = _consts.TTL_ULTRIX
        elif sys.platform.find('dec') != -1:
            ttl = _consts.TTL_DEC
        else:
            ttl = _consts.TTL_LINUX

        expected = ("\x45\x00\x00\x28\x03\xe8\x00\x00"
                    "%c\x06\x79\x00\x7f\x00\x00\x01"
                    "\x7f\x00\x00\x01") % chr(ttl)

        p = Packet()
        p.include(IP(src="127.0.0.1",
                    dst="127.0.0.1",
                    _id=1000,
                    _checksum=0x7900))
        p.include(TCP(srcport=123, dstport=321, flags='psh'))

        expected += ("\x00\x7b\x01\x41\x00\x00\x00\x00"
                    "\x00\x00\x00\x01\x50\x08\x02\x00"
                    "\xae\x1d\x00\x00")
        assert expected == p.get_raw()

        p.include(Payload(data="UMPA"))

        expected = ("\x45\x00\x00\x2c\x03\xe8\x00\x00"
                    "%c\x06\x79\x00\x7f\x00\x00\x01"
                    "\x7f\x00\x00\x01"
                    "\x00\x7b\x01\x41\x00\x00\x00\x00"
                    "\x00\x00\x00\x01\x50\x08\x02\x00"
                    "\x08\x8b\x00\x00") % chr(ttl)

        expected += "\x55\x4d\x50\x41"
        assert expected == p.get_raw()
Ejemplo n.º 8
0
    def test_get_raw(self):
        if sys.platform.find('linux') != -1:
            ttl = _consts.TTL_LINUX
        elif sys.platform.find('darwin') != -1:
            ttl = _consts.TTL_MACOS
        elif sys.platform.find('win') != -1:
            ttl = _consts.TTL_WINDOWS
        elif sys.platform.find('freebsd') != -1:
            ttl = _consts.TTL_FREEBSD
        elif sys.platform.find('os2') != -1:
            ttl = _consts.TTL_OS2
        elif sys.platform.find('sunos') != -1:
            ttl = _consts.TTL_SUNOS
        elif sys.platform.find('aix') != -1:
            ttl = _consts.TTL_AIX
        elif sys.platform.find('irix') != -1:
            ttl = _consts.TTL_IRIX
        elif sys.platform.find('solaris') != -1:
            ttl = _consts.TTL_SOLARIS
        elif sys.platform.find('ultrix') != -1:
            ttl = _consts.TTL_ULTRIX
        elif sys.platform.find('dec') != -1:
            ttl = _consts.TTL_DEC
        else:
            ttl = _consts.TTL_LINUX

        expected = ("\x45\x00\x00\x28\x03\xe8\x00\x00"
                    "%c\x06\x79\x00\x7f\x00\x00\x01"
                    "\x7f\x00\x00\x01") % chr(ttl)

        p = Packet()
        p.include(
            IP(src="127.0.0.1", dst="127.0.0.1", _id=1000, _checksum=0x7900))
        p.include(TCP(srcport=123, dstport=321, flags='psh'))

        expected += ("\x00\x7b\x01\x41\x00\x00\x00\x00"
                     "\x00\x00\x00\x01\x50\x08\x02\x00"
                     "\xae\x1d\x00\x00")
        assert expected == p.get_raw()

        p.include(Payload(data="UMPA"))

        expected = ("\x45\x00\x00\x2c\x03\xe8\x00\x00"
                    "%c\x06\x79\x00\x7f\x00\x00\x01"
                    "\x7f\x00\x00\x01"
                    "\x00\x7b\x01\x41\x00\x00\x00\x00"
                    "\x00\x00\x00\x01\x50\x08\x02\x00"
                    "\x08\x8b\x00\x00") % chr(ttl)

        expected += "\x55\x4d\x50\x41"
        assert expected == p.get_raw()