Alex Rebell
Alex Rebell

Reputation: 374

How to get information about parameters

Good afternoon. Please tell me how I can get information on each parameter of a package? For example, I look at what parameters the IP packet has:

ls(IP)

outcome:

version : BitField (4 bits) = (4)
ihl : BitField (4 bits) = (None)
tos : XByteField = (0)
len : ShortField = (None)
id : ShortField = (1)
flags : FlagsField (3 bits) = (<Flag 0 ()>)
frag : BitField (13 bits) = (0)
ttl : ByteField = (64)
proto : ByteEnumField = (0)
chksum : XShortField = (None)
src : SourceIPField = (None)
dst : DestIPField = (None)
options : PacketListField = ([])

My question is, how can I get information about the parameter ihl, tos, if, and so on... i.e., what can I specify in these parameters, what values a particular parameter supports? Thank you very much.

Upvotes: -1

Views: 256

Answers (2)

furas
furas

Reputation: 142889

You can list of all methods and fields in class

dir(IP)

but it doesn't gives details.

BTW: you can filter them as any other list

list(name for name in dir(IP) if 'raw' in name)

and it can be useful when you forgot some name and want to find it.


You can display information from docstrings in code

help(IP)

help(IP.ihl)

and it can gives some details.


And finally you can search in documentation and you find scapy.layers.inet.IP


But probably to understand some fields you have to simply learn TPC/IP and other protocols which scapy only use - it doesn't decide how protocols are defined.

Upvotes: 1

Diego Magalh&#227;es
Diego Magalh&#227;es

Reputation: 1762

This may help you. Use Python built-in function dir().

from datetime import datetime

dir(datetime)

['add', 'class', 'delattr', 'dir', 'doc', 'eq', 'format', 'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'ne', 'new', 'radd', 'reduce', 'reduce_ex', 'repr', 'rsub', 'setattr', 'sizeof', 'str', 'sub', 'subclasshook', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fold', 'fromisocalendar', 'fromisoformat', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timestamp', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']

Upvotes: 1

Related Questions