Python mock ICMP Packet

Source: Internet
Author: User

Mainly use Scapy to complete

Basic Environment

VM1 (192.168.1.226)

|

|

VM2 (192.168.1.125)

VM1 encapsulation ICMP packets sent to VM2

VM1 script:

#! /usr/bin/env pythonfrom scapy.all Import *target = "192.168.1.125" IP = IP () ICMP = ICMP () ip.dst = Targeticmp.type = 0icmp.c Ode = 0send (ip/icmp)

VM2 Script

From scapy.all import *packetcount = 0def customAction (packet):    global packetcount    Packetcount + = 1    If Len ( Packet) >0 and Len (Packet[0]) >1:      if Hasattr (packet[0][1], ' src ') and packet[0][1].src = = ' 192.168.1.226 ' and packet[0][1].dst== ' 192.168.1.125 ':        print packet.show ()    #return "packet #%s:%s ==>%s"% (Packetcount, PACKET[0][1].SRC, PACKET[0][1].DST)    return Nonesniff (filter= "IP", prn=customaction)

  

This way we can use iptables to add rules that restrict ICMP to various types of code packages.

Reference

Http://www.nthelp.com/icmp.htmlhttps://www.oregontechsupport.com/articles/icmp.txt

Python mock ICMP Packet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.