Re: Starting Python... some questions
Jordan, Thinker, Steven, Thanks for your responses. Makes more sense now! I can run my program from the console. I added the self parameter to the the chassis_id function, however I now have a problem and question regarding encoding MAC addresses for a struct. What string format am I supposed to use? Also, I think I will get rid of Scapy in my small program. Any references I can use to easily send (no need to receive) a packet with a Layer 1 and 2 only? (i.e. only Ethernet and LLDP - no need for IP, UDP, TCP etc. I wish to create something like Ethernet | LLDP msg1 | LLDP msg2 | ... | LLDP msgn) Thanks! This is what I got now: #!/usr/bin/python import scapy import struct class lldp_class: def __init__(self): self.chassis_id_tlv = None def chassis_id(self, subtype, chassis_info): if subtype == 4: chassis_data = struct.pack("!B",chassis_info) subtype_data = struct.pack("!B",subtype) self.chassis_id_tlv = subtype_data + chassis_data def __main__(): p = lldp_class() p.chassis_id(4, "01:80:C2:00:00:0E") payload = p.chassis_id_tlv ether = scapy.Ether(dst="01:02:03:04:05:06") fullpayload = ether + payload sendp(fullpayload) __main__() Expecting? Get great news right away with email Auto-Check. Try the Yahoo! Mail Beta. http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Starting Python... some questions
All, thank you for your responses. I learned much and made some modifications in my small program. Currently I am attempting to put together a packet that contains a Python message (created using struct.pack) and a Scapy message (Ether()). Having a packet with combined payload from Python and Scapy doesn't seem to work the way I do it: ether = scapy.Ether(dst="01:02:03:04:05:06") payload = ether + payload (where payload is the chassis_id) I get as error: File "lldp.py", line 23, in main fullpayload = ether + payload TypeError: unsupported operand type(s) for +: 'Ether' and 'str' I'm thinking instead to just use Python to create the Ethernet Frame as well and then send the packet off. How difficult is this? I could only find references online on how to send TCP/UDP packets but no information on how to send a packet with a Layer1 and Layer2 only. The ethernet frame should only contain a destination MAC, a source MAC and a type (88cc). Any advice on how to create such a packet and send it? (if anyone knows of an easy way to use a hybrid of Python and Scapy, that's fine by me as well). Thanks! class lldp_class: def __init__(self): self.chassis_id_tlv = None def chassis_id(self, subtype, chassis_info): if subtype == 4: chassis_data_int = [int(x,16) for x in chassis_info.split(":")] chassis_data = struct.pack("6B", *chassis_data_int) subtype_data = struct.pack("!B",subtype) self.chassis_id_tlv = subtype_data + chassis_data def main(): p = lldp_class() p.chassis_id(4, "01:80:C2:00:00:0E") payload = p.chassis_id_tlv ether = scapy.Ether(dst="01:02:03:04:05:06") fullpayload = ether + payload sendp(fullpayload) main() Never miss an email again! Yahoo! Toolbar alerts you the instant new Mail arrives. http://tools.search.yahoo.com/toolbar/features/mail/ -- http://mail.python.org/mailman/listinfo/python-list