Kaynağa Gözat

Add docstring and parameter types to function

dustin.born 7 yıl önce
ebeveyn
işleme
ad5cce0382
1 değiştirilmiş dosya ile 15 ekleme ve 2 silme
  1. 15 2
      code/Iteration1/IPPacketGenerator.py

+ 15 - 2
code/Iteration1/IPPacketGenerator.py

@@ -1,8 +1,21 @@
 from scapy.layers.inet import IP, Ether, TCP
 from scapy.packet import Raw
 
-def generate_ip_packet(ip_src="192.168.64.32", ip_dst="192.168.64.48", mac_src="56:6D:D9:BC:70:1C", mac_dst="F4:2B:95:B3:0E:1A",
-					   port_src=1337, port_dst=6442, tcpflags="S", payload = ""):
+def generate_ip_packet(ip_src:str="192.168.64.32", ip_dst:str="192.168.64.48", mac_src:str="56:6D:D9:BC:70:1C", 
+					   mac_dst:str="F4:2B:95:B3:0E:1A", port_src:int=1337, port_dst:int=6442, tcpflags:str="S", payload:str=""):
+	"""
+    Builds an IP packet with the values specified by the caller. If a parameter was not specified by the caller, 
+    it is set to a default value.
+    :param ip_src: the source IP address of the IP header
+    :param ip_dst the destination IP address of the IP header
+    :param mac_src: the source MAC address of the MAC header
+    :param mac_dst: the destination MAC address of the MAC header
+    :param port_src: the source port of the TCP header
+    :param port_dst: the destination port of the TCP header
+    :param tcpflags: the TCP flags of the TCP header
+    :param payload: the payload of the packet
+    :return: the corresponding IP packet
+    """
 
 	ether = Ether(src=mac_src, dst=mac_dst)
 	ip = IP(src=ip_src, dst=ip_dst)