zoukankan      html  css  js  c++  java
  • scapy examples

    The following lists scapy examples based on experiments performed on the below topology. The topology contains two PC’s , Ubuntu and Windows 7. Scapy is setup on Ubuntu system.

    Example 1 – How to send a ping packet from Scapy on Ubuntu to Windows 7.

    ip=IP() # Creates an IP header
    ip.src=’192.168.1.25′ # Source address in the IP header is configured with IP address of ubuntu.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    icmp=ICMP() # Creates an ICMP header
    icmp.type=8 # Type value inserted in ICMP header as 8 for ping crafting
    icmp.code=0 # Code value inserted in ICMP header as 0 for ping crafting.
    send(ip/icmp) # Sending ping packet.

    Join our Course to Build Network Automation tools and scripts with Python and Scapy on Udemy

    Example 2 – How to send a ping packet from Scapy on Ubuntu to Windows 7 with Random Source address.

    ip=IP() # Creates an IP header
    ip.src=RandIP() # Configures the source address in the IP header with a random IP address.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    icmp=ICMP() # Creates an ICMP header
    icmp.type=8 # Type value inserted in ICMP header as 8 for ping crafting
    icmp.code=0 # Code value inserted in ICMP header as 0 for ping crafting.
    send(ip/icmp) # Sending ping packet.

    Join our Course to Build Network Automation tools and scripts with Python and Scapy on Udemy

    ——————————————————————————————————————-

    ——————————————————————————————————————-

    Example 3 – How to create a TCP SYN to port 80 on Windows 7 from Scapy on Ubuntu with Random Source address.

    tcp=TCP() # Creates a TCP header
    tcp.dport=80 # Configures the destination port in the TCP header with port 80.
    tcp.flags=’S’ # Configure the flag in the TCP header with the SYN bit.
    ip=IP() # Creates an IP header
    ip.src=’192.168.1.25′ # Source address in the IP header is configured with IP address of ubuntu.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    send(ip/tcp) # Sending tcp packet.

    ——————————————————————————————————————-
    Join our Course to Build Network Automation tools and scripts with Python and Scapy on Udemy

    ——————————————————————————————————————-

    Example 4 – How to print the TTL value of a received ping reply packet using Scapy

    ip=IP() # Creates an IP header
    ip.src=’192.168.1.25′ # Source address in the IP header is configured with IP address of ubuntu.
    ip.dst =’ 192.168.1.100′ # Destination address in the IP header is configured with the IP address of Windows 7.
    icmp=ICMP() # Creates an ICMP header
    icmp.type=8 # Type value inserted in ICMP header as 8 for ping crafting
    icmp.code=0 # Code value inserted in ICMP header as 0 for ping crafting.
    p=sr1(ip/icmp) # Sends and receives the packet in the variable p
    p.ttl # Displays the ttl value in the received IP header.

    Example 4 – How to create an ARP request packet with Scapy on Ubuntu to Windows 7

    ether=Ether() # Creates an ethernet header
    ether.src=’00:e0:1c:3c:22:b4′ # Configures the source mac address in the ethernet header with the mac-address of ubuntu system
    ether.dst=’FF:FF:FF:FF:FF:FF’ Configures the destination mac address in the ethernet header with broadcast for ARP request packet
    arp=ARP() # Creates an ARP header
    arp.op=1 # Configures the ARP type as 1
    arp.hwsrc=’00:e0:1c:3c:22:b4′ # Configures the sender mac address in the ethernet header with the mac-address of ubuntu system
    arp.psrc=’192.168.1.25′ # Configures the sender IP address in the ethernet header with the IP address of ubuntu system
    arp.pdst=’192.168.1.100′ # Configures the target IP address in the ethernet header with the IP address of ubuntu system
    arp.hwdst=’00:00:00:00:00:00′ # Configures the target mac address in the ethernet header as NULL
    p=srp1(ether/arp) # Sends the packet at layer 2 using the command srp1, appending the ether and arp headers.

  • 相关阅读:
    Spring HttpIvoker实现Java的远程调用
    基于struts2框架文件的上传与下载
    12月9号linux学习
    2019.7.7 练习题
    题解 儿童节继续欢乐赛
    Winfroms看看吧客官~
    group by应用
    基于Windows Azure 搭建基于SharePoint 2010 Intranet、Extranet、Internet (1): 安装SharePoint 2010
    基于Windows Azure 搭建基于SharePoint 2010 Intranet、Extranet、Internet (2): 创建并发布SharePoint Intranet站点
    Inside Microsoft SharePoint 2010 简译(1): SharePoint 2010开发者路线图
  • 原文地址:https://www.cnblogs.com/dream397/p/13710218.html
Copyright © 2011-2022 走看看