Skip to content

About function 'sendpacket' #103

Open
@starsyiyi

Description

@starsyiyi

How to use the function 'sendpacket' ?

the following error info is “<class 'TypeError'> expected LP_c_ubyte instance instead of bytes”, how to use the function ? thanks a lot

h = pcap.findalldevs()
h
['\Device\NPF_{0E865733-C420-433F-A842-1CFAF01D0584}', '\Device\NPF_{4AC140BE-5CCB-4CEC-A5C6-45EB5670271E}', '\Device\NPF_{6AFC5285-5C62-40DF-86C6-075CA7631080}', '\Device\NPF_{7D3008E3-2FE8-4871-8063-520F4CC3E1B6}', '\Device\NPF_{CB8D1936-C71A-44E3-84B8-0C372898B1C6}', '\Device\NPF_{785A38C8-001C-4D02-86D9-6D1051B3C5AB}', '\Device\NPF_{3131428A-0B14-410B-9BB1-50C965A1B8CB}']
hd = pcap.pcap('\Device\NPF_{4AC140BE-5CCB-4CEC-A5C6-45EB5670271E}')
hd
<pcap._pcap.pcap object at 0x000002496F8F57C0>
listPkt = [0xea,0x00,0x01,0x02,0x03,0xeb,0x00,0x01,0x02,0x03,0x77,0x88]
for i in range(100):
listPkt.append(i)

listPkt
[234, 0, 1, 2, 3, 235, 0, 1, 2, 3, 119, 136, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
pkt = bytes(listPkt)
pkt
b'\xea\x00\x01\x02\x03\xeb\x00\x01\x02\x03w\x88\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abc'

hd.sendpacket(pkt)
Traceback (most recent call last):
File "<pyshell#59>", line 1, in
hd.sendpacket(pkt)
File "C:\Python39\lib\site-packages\pcap_pcap.py", line 312, in sendpacket
if _pcap.sendpacket(self.__pcap, buf, len(buf)) == -1:
ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected LP_c_ubyte instance instead of bytes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions