How can I print only whenever i got ip otherwise wait for next packet

  dhcp, ip, networking, pyshark, python-3.x

Whenever i try to print it will raise error if actual ip will not come with packet. What should i do that it will print only whenever i got actual ip otherwise wait for next packet

import pyshark

capture = pyshark.LiveCapture(interface='wlo2', bpf_filter='udp port 68')
capture.sniff_continuously(packet_count=16)

emp_ip = '0.0.0.0'
emp_list = list()

for packet in capture:
    if (packet.dhcp.hw_mac_addr not in emp_list) and (packet.dhcp.option_requested_ip_address != emp_ip):
        mac_address = packet.dhcp.hw_mac_addr
        emp_list.append(mac_address)

        client_ip = packet.dhcp.option_requested_ip_address
        print(packet.sniff_time, client_ip, mac_address, packet.dhcp.option_hostname, packet.dhcp.option_vendor_class_id)

else:
    pass

Source: Python-3x Questions

LEAVE A COMMENT