一个很newbee的例子,可惜还得改

 import sys
import time import socket
import struct import random def SendPacketData (Buffer = None , DestIP = "127.0.0.1" , DestPort = 10000) :
"""SendPacketData""" if Buffer is None :
return False try:
Socket = socket.socket(socket.AF_INET,socket.SOCK_RAW)
Socket.setsockopt(socket.IPPROTO_IP,socket.IP_HDRINCL,1)
Socket.setsockopt(socket.SOL_SOCKET,socket.SO_SNDTIMEO,2000) except:
Socket.close()
return False try:
Socket.sendto(Buffer,0,(DestIP , DestPort)) except:
Socket.close() return True def SetPacketAddress (Number = 1) :
"""SetPakcetAddress""" return [".".join(["%d" % random.randint(1 , 0xFF) for i in range(0,4)]) for n in range(0 , Number)] def SetPacketData (Length = 32) :
"""SetPacketData""" return "".join(["%s" % chr(random.randint(0 , 255)) for n in range(Length)]) def SetPacketCheckSum (Buffer = None) :
"""SetPacketCheckSum""" if Buffer == None :
return False if len(Buffer) % 2 :
Buffer += '/0' return ~sum([(ord(Buffer[n + 1]) << 8) + ord(Buffer[n]) for n in range(0 , len(Buffer) , 2)])
#or return ~sum([ord(Buffer[n]) + ord(Buffer[n + 1]) * 256 for n in range(0 , len(Buffer) , 2)]) def SynSendInit (DestIP = "127.0.0.1" , DestPort = 80) :
"""SynSendInit""" IpHdrLen = 20
TcpHdrLen = 20 IpVerlen = (4 << 4 | IpHdrLen / 4)
IpTotal_len = socket.htons(IpHdrLen + TcpHdrLen) IpDestIP = struct.unpack('i',socket.inet_aton(DestIP))[0]
IpSourceIP = struct.unpack('i',socket.inet_aton(SetPacketAddress()[0]))[0] TcpSport = socket.htons(random.randint(1024 , 65000))
TcpDport = socket.htons(DestPort) TcpLenres = (TcpHdrLen / 4 << 4 | 0)
TcpSeq = socket.htonl(int(time.time())) Buffer = struct.pack("LLBBHHHLLBBHHH",IpSourceIP,IpDestIP,0,socket.IPPROTO_TCP,socket.htons(TcpHdrLen)
,TcpSport,TcpDport,TcpSeq,0,TcpLenres,2,socket.htons(8192),0,0)
TcpChecksum = SetPacketCheckSum(Buffer) Buffer = struct.pack("BBHHHBBHLL",IpVerlen,0,IpTotal_len,1,0x40,255,socket.IPPROTO_TCP,0,IpSourceIP,IpDestIP)
IpChecksum = SetPacketCheckSum(Buffer) tcpcsp = struct.pack("L",TcpChecksum)
ipcsp = struct.pack("L",IpChecksum) return struct.pack("BBHHHBBHLLHHLLBBHHH",IpVerlen,0,IpTotal_len,1,0x40,255,socket.IPPROTO_TCP
,(ord(ipcsp[1]) << 8) + ord(ipcsp[0]),IpSourceIP,IpDestIP
,TcpSport,TcpDport,TcpSeq,0,TcpLenres,2,socket.htons(8192)
,(ord(tcpcsp[1]) << 8) + ord(tcpcsp[0]),0) def SynSendMain (DestIP = "127.0.0.1" , DestPort = 80) :
"""SynSendMain""" return SendPacketData(SynSendInit(DestIP , DestPort) , DestIP , DestPort) if __name__ == "__main__" :
try:
SynSendMain()
except:
pass

raw socket的更多相关文章

  1. C#的Raw Socket实现网络封包监视

    同Winsock1相比,Winsock2最明显的就是支持了Raw Socket套接字类型,使用Raw Socket,可把网卡设置成混杂模式,在这种模式下,我们可以收到网络上的IP包,当然包括目的不是本 ...

  2. raw socket遇上windows

    最近很长一段时间内又捡起了大学时丢下的网络协议,开始回顾网络协议编程,于是linux系统成了首选,它让我感到了无比的自由,可以很通透的游走于协议的各层. 最初写了个ARP欺骗程序,很成功的欺骗了win ...

  3. Path Analyzer Pro出现raw socket问题

    使用windows7,8以及10平台运行一个traceroute liketools软件,名为Path Analyzer Pro 2.7,遇到raw socket问题,如图: 原因是raw socke ...

  4. Raw Socket vs Stream Socket vs datagram socket,原始套接字与流式套接字与数据报套接字

    https://opensourceforu.com/2015/03/a-guide-to-using-raw-sockets/ In this tutorial, let’s take a look ...

  5. C#之Raw Socket实现网络封包监视

    同Winsock1相比,Winsock2最明显的就是支持了Raw Socket套接字类型,使用Raw Socket,可把网卡设置成混杂模式,在这种模式下,我们可以收到网络上的IP包,当然包括目的不是本 ...

  6. 【VS开发】raw socket 的例子

    raw socket 的例子 一. 摘要    Raw Socket: 原始套接字    可以用它来发送和接收 IP 层以上的原始数据包, 如 ICMP, TCP, UDP... int sockRa ...

  7. raw, SOCK_RAW - Linux IPv4 raw socket.

    总 览 #include <sys/socket.h> #include <netinet/in.h> raw_socket = socket(PF_INET, SOCK_RA ...

  8. C#之Raw Socket网络封包监视源码

    大家可以建立一个Windows Form应用程序,在下面的各个文件中添加对应的源码: //RawSocket.csnamespace ReceiveAll{ using System; using S ...

  9. Raw Socket(原始套接字)实现Sniffer(嗅探)

    参考资料: https://www.xuebuyuan.com/3190946.html https://blog.csdn.net/zxygww/article/details/52093308 i ...

随机推荐

  1. linux修改系统编码

    Windows的默认编码为GBK,Linux的默认编码为UTF-8.在Windows下编辑的中文,在Linux下显示为乱码.一种方法是在windows进行转码,比如使用ue工具在文件-->转换 ...

  2. HttpClient_httpclient 4.3.1 post get的工具类

    package com.ryx.util; import java.util.ArrayList; import java.util.List; import java.util.Map; impor ...

  3. Spring整合Hibernate之AnnotationSessionFactoryBean与LocalSessionFactoryBean

    spring集成hibernate由两种形式 1.继续使用Hibernate的映射文件*.hbm.xml 2.使用jpa形式的pojo对象, 去掉*.hbm.xml文件 一.继续使用Hibernate ...

  4. 关于 微软必应词典客户端(pc) 的案例分析

    第一部分 调研,评测 ●评测 bug one 在词典界面中搜完单词后,将鼠标移到英文例句上的单词时,会显示对应的中文翻译,而当移到短语时则不对应中文翻译. bug two 用orc强力取词,查询如上图 ...

  5. 淘宝前端工程师:国内WEB前端开发十日谈

    一直想写这篇"十日谈",聊聊我对Web前端开发的体会,顺便解答下周围不少人的困惑和迷惘.我不打算聊太多技术,我想,通过技术的历练,得到的反思应当更重要. 我一直认为自己是" ...

  6. android-数据存储之远程服务器存储

    一.如何编码实现客户端与服务器端的交互 <一>JDK内置原生API HttpUrlConnection <二>Android内置的包装API HttpClient浏览器 < ...

  7. *HDU 1286,2824欧拉函数

    #include<iostream> #include<string> #include<cstdio> #include<cmath> #includ ...

  8. 利用background-attachment做视差滚动效果

    视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验.作为今年网页设计的热点趋势,越来越多的网站应用了这项技术. 不明白的可以先看 ...

  9. 了解C++默认编写并调用哪些函数

    概念:编译器可以暗自为class创建default构造函数.copy构造函数.copy assignmengt构造函数,以及析构函数. 比如你写下:struct Node { }; 这就好像你写下这样 ...

  10. php数组序列化serialize与unserialize

    $arr=array('1','2','3');echo serialize($arr); //序列化 a:3:{i:0;s:1:"1";i:1;s:1:"2" ...