Skip to content

Instantly share code, notes, and snippets.

@lamehost
Last active December 23, 2021 13:42
Show Gist options
  • Save lamehost/4b2fa2aa0900ef74436d634f941728b6 to your computer and use it in GitHub Desktop.
Save lamehost/4b2fa2aa0900ef74436d634f941728b6 to your computer and use it in GitHub Desktop.
Simple CDP message generator
"""
Simple CDP message generator.
You have to "pip install scapy" to make it work
"""
import argparse
from time import sleep
import socket
from scapy.all import *
def main():
# Parse CLI arguments
parser = argparse.ArgumentParser(
description='Sends CDP hello packets'
)
parser.add_argument(
'-i',
'--interval',
type=int,
help='Amount of seconds between each message',
default=30
)
parser.add_argument(
'interface',
type=str,
help='Interface to bind to'
)
parser.add_argument(
'-v',
'--verbose',
action='store_true',
help='Enable verbose logging',
default=False
)
args = parser.parse_args()
# Load CDP module
load_contrib('cdp')
# Find hostname
hostname = socket.gethostname()
# Send packet loop
sendp(
Ether(
dst="01:00:0c:cc:cc:cc")/LLC()/SNAP(OUI=0xc, code=0x2000)/CDPv2_HDR(msg=[
CDPMsgDeviceID(val=hostname),
CDPMsgCapabilities(cap=["Host"]),
CDPMsgPortID(iface=args.interface)
]
),
inter=args.interval,
loop=1,
verbose=args.verbose,
iface=args.interface
)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment