Python-scapy Study Notes-(1), pythonscapy

Source: Internet
Author: User

Python-scapy Study Notes-(1), pythonscapy

Main function: sniff

Sniff (filter = "", iface = "any", prn = function, count = N)

The filter parameter allows us to specify a BPF (Wireshark type) filter for Scapy sniffing data packets, or leave it blank to sniff all data packets.

For example, sniffing all HTTP data packets and tcp port 80 BPF Filtering

The iface parameter sets the NIC to be sniffed by the sniffer. If it is left blank, all NICs are sniffed.

Example: wlan0

The prn parameter specifies the callback function called when packets that meet the filter conditions are sniffed. This callback function uses the received data packet object as the unique parameter.

For example:

Def pack_callback (packet ):
Print packet. show ()

Sniff (prn = pack_callback, iface = "wlan0", count = 1)

The count parameter specifies the number of data packets to be sniffed. If left blank, the default value is unlimited.

 

Add the source code of the sniffer mail.

 

#coding:utf-8
from scapy.all import *
def pack_callback(packet):
print packet.show()
if packet[TCP].payload:
mail_packet=str(packet[TCP].payload)
if "user" in mail_packet.lower() or "pass" in mail_packet.lower():
print "Server:%s"%packet[IP].dst
print "%s"%packet[TCP].payload

sniff(filter="tcp port 110 or tcp port 25 or tcp port 143",prn=pack_callback,iface="wlan0",count=0)

 

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.