I'm using pyshark to parse pcap files. I want to access layer fields using variable as shown in simple example below:
For example to access ntp server ip:
p = cap[0]
print(p.bootp.option_ntp_server)
However, I want to access it like this:
option_list = {
"12": "option_hostname",
"60": "option_vendor_class_id",
"43": "option_ntp_server"
}
p = cap[0]
print(p.bootp.%s %(option_list["43"]))
Of course this kind of access is not possible. So I tried to use getattr()
like this:
getOption = getattr(p.bootp, option_list["43"])
getOption()
And it gave me following error:
'LayerFieldsContainer' object is not callable
It seems pyshark packet or layer classes is not callable.
How I can access layer fields using variable? Or can you suggest me another method to access options using option type numbers? Because I want to access this fields using option type numbers (Like option 12, option 43), not using titles.