The problem in code is that if a field is missed then it raises error and if I except the error then it will not show anything
import pyshark
from tabulate import tabulate
capture = pyshark.FileCapture('/home/sipl/Downloads/DHCP.cap', display_filter='udp.port eq 67')
# capture2 = pyshark.LiveCapture(interface='wlo2', display_filter='arp')
d = dict()
for packet in capture:
try:
d['mac'] = packet.dhcp.hw_mac_addr
d['hname'] = packet.dhcp.option_hostname
d['vend'] = packet.dhcp.option_vendor_class_id
except AttributeError:
pass
try:
d['srvrid'] = packet.dhcp.option_dhcp_server_id
d['smask'] = packet.dhcp.option_subnet_mask
d['DNS'] = packet.dhcp.option_domain_name_server
d['Domain'] = packet.dhcp.option_domain_name
except AttributeError:
pass
try:
d['ip'] = packet.dhcp.option_requested_ip_address
except AttributeError:
pass
try:
table = {'Mac': [d['mac']], 'IP': [d['ip']], 'host': [d['hname']],'vendor': [d['vend']], 'Server id': [d['srvrid']],
'Sub mask': [d['smask']], 'DNS': [d['dns']], 'Domain': [d['Domain']]}
print(tabulate(table, headers='keys'))
except KeyError:
continue
I want that if a field is missed then it store the incoming fields i got in a packet and show in the table, for empty field it doesn't show anything and leave the field empty in table. Basically I want that it stores the incoming field and prints in table and didn't raise error for the missed field. I'm trying it now on fileCapture to check working but i need to do this on liveCapture