Interactive Console
PacketGen provides an interactive console: pgconsole. It may be used to quickly write and test some pieces of code.
pgconsole uses IRB, or Pry if it is installed. It includes PacketGen class methods and PacketGen::Utils ones to simplify access to them.
Quick access to PacketGen methods
gen, parse, capture, read and write are quickly accessible:
pg> pkt = gen('Eth', src: '00:00:00:00:00:01', dst: '00:00:00:00:00:02')
=> -- PacketGen::Packet -------------------------------------------------
---- PacketGen::Header::Eth ------------------------------------------
MacAddr dst: 00:00:00:00:00:02
MacAddr src: 00:00:00:00:00:01
Int16 ethertype: 0 (0x0000)
pg>
pg> parse(pkt.to_s, first_header: 'Eth')
=> -- PacketGen::Packet -------------------------------------------------
---- PacketGen::Header::Eth ------------------------------------------
MacAddr dst: 00:00:00:00:00:02
MacAddr src: 00:00:00:00:00:01
Int16 ethertype: 0 (0x0000)
pg> write 'packet.pcapng', [pkt]
pg> pkts = read('packet.pcapng')
=> [-- PacketGen::Packet -------------------------------------------------
---- PacketGen::Header::Eth ------------------------------------------
MacAddr dst: 00:00:00:00:00:02
MacAddr src: 00:00:00:00:00:01
Int16 ethertype: 0 (0x0000)
]
pg>
pg> capture { |pkt| p pkt }local configuration
pgconsole provides quick access to local network configuration through config, a PacketGen::Config object:
This local configuration may be used to forge packets:
Utils
To ease tests, Methods from PacketGen::Utils module are quickly accessible from pgconsole:
Utils methods are:
Last updated