Wireshake grab bag, fly autumn send message, python

Source: Internet
Author: User
Tags uuid

Http://wenku.baidu.com/link?url=Xze_ Jy8t15pqi9mblrptxwf2d6mp-32xb6uwue6tsumitrdheje-ju87wldedbgui5mfyhtbfn4qekxfq5gvamnx9o5a3ngq1f-sma8lyja

# Coding=utf-8#import Socket #udp =socket.socket (socket.af_inet,socket. SOCK_DGRAM) #udp. Connect (' localhost ', 2425) #udp. Send (' 1:100:aaaaa:zhang:32:hello every body ') #udp. Send (' 1_lbt4_ 10#32899#002481627512#0#0#0:1289671407:flyingzl:flyingz l:288: A day, like March ') #coding =utf-8import dpktimport Sendpktfrom socket import Inet_aton from time import strftimeimport socketimport typesimport uuid# Local Gateway MAC address can be obtained as follows: # c:\users\administrator>arp-a# interface: 192.168.0.100---0xb# Internet address Physical Address type # 192.168.0.1 00-03-47-c a-e4-5c dynamic mask_mac= ' 4c-5e-0c-b1-50-29 ' def get_local_mac (): ' Get native MAC address ' mac=uuid.uuid1 (). HEX[-12:] return '-'. Joi N ([mac[(I-1) *2:2*i] for I in range (1,7)]) def send_msg (Kwargs): "Send message, Kwargs parameter is a Dict object" if Type (Kwargs) is not types. dicttype:return# Native IP address local_ip=kwargs.get (' src ', Socket.gethostbyname (Socket.gethostname ())) #转码后的源ip地址src_ip = Inet_aton (LOCAL_IP) #转码后的目的ip地址dst_ip =inet_aton (kwargs.get (' DST ')) #本机mac地址local_mac =kwargs.get (' Src_mac ', get_ Local_Mac ()) #转码后的源mac地址src_mac =pack_mac (Local_mac) #判断remote_ip和local_ip是否在同一个网段 # transcoding the destination MAC address Dst_mac=pack_mac ( Kwargs.get (' Dst_mac ')) if Trans (local_ip) ==trans (Kwargs.get (' DST ')) Else Pack_mac (MASK_MAC) host=kwargs.get (' Host ', Socket.gethostname ()) user=kwargs.get (' User ', ' user ') Msg=kwargs.get (' msg ', ' Hello ') #找到第一个网络端口, modify it according to your own circumstances # Students with VirtualBox, VMware, or wireless cards have to modify their own device=sendpkt.findalldevs () [0] #飞鸽监听本地的UDP 2425 Port udp=dpkt.udp.udp (dport=242 5,sport=2425) #向飞鸽发送消息命令字 #6291458表示下线 #6291457表示上线 #288表示发送信息 #如果是飞秋, 65664 This state will be displayed on each other as two suns msg= "1_lbt4_10#65664#%s# 0#0#0:%s:%s:%s:288:%s "% (local_mac.replace ('-', '), int (strftime ('%m%d%h%m%s ')) +100000000,user,host,msg) msg= Msg.encode ("Utf-8") udp.data+=msg Udp.ulen=len (UDP) Ip=dpkt.ip.ip (src=src_ip,dst=dst_ip,data=udp,p=dpkt.ip.ip_pro TO_UDP) #重新计算ip的长度, otherwise the message cannot be sent out Ip.len=len (IP) ether=dpkt.ethernet.ethernet (Dst=dst_mac, Src=src_ma C, type=0x0800, DATA=IP) sendpkt.sendpacket (str (ether), DeviCE) def trans (ip,mask= ' 255.255.255.0 '): ' Determine whether two IP addresses are in the same network segment ' ' Str=[' Ip=ip.split (".")   Mask=mask.split (".") For Index,item in Enumerate (IP): str.append (int (item) &int (Mask[index])) return str def pack_mac (mac,pattern = '-'): ' network card address switched to Ethernet MAC address for example "08-00-27-ba-f7-e5" to "\x08\x00 ' \xba\xf7\xe5" "Mac=mac.split (Pattern.lower ()) Retu RN "". Join ([Chr (int (' 0x ' +x,16)) for x in Mac]) if __name__== "__main__": s={' src ': ' 192.168.155.1 ', ' DST ' : ' 192.168.155.1 ', ' src_mac ': ' Ff-ff-ff-ff-ff-ff ', #这个地址最好别写错, you can see your friend's MAC address ' Dst_mac ' from the Flying Pigeon: ' ff-ff-ff-f  F-ff-ff ', ' host ': ' Haha ', ' user ': ' hehe ', ' msg ': ' Overtime? '   } send_msg (s)

Wireshake grab, fly autumn send message, Python

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.