使用Scapy发送TCP数据包

时间:2018-07-15 18:41:46

标签: java scapy mininet

我想使用Scapy从mininet主机向Floodlight控制器发送TCP数据包。我使用以下代码创建并发送消息:

from scapy.all import IP, TCP, send

data = "Hi there"
a = IP(dst="127.0.0.1")/TCP(dport=6653)/data
send(a)

我还将此代码添加到了Floodlight模块的“接收数据包”部分,以便当TCP数据包到达控制器时,它将打印其目标端口,源端口和...

     @Override
     public net.floodlightcontroller.core.IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
         Ethernet eth =
                 IFloodlightProviderService.bcStore.get(cntx,
                                             IFloodlightProviderService.CONTEXT_PI_PAYLOAD);

         if (eth.getEtherType() == EthType.IPv4) {
                /* We got an IPv4 packet; get the payload from Ethernet */
                IPv4 ipv4 = (IPv4) eth.getPayload();
                logger.warn ("IP Packet Received!:-)");

                logger.warn ("ipv4.getSourceAddress(): "+ipv4.getSourceAddress().toString());
                logger.warn ("ipv4.getDestinationAddress(): "+ipv4.getDestinationAddress().toString());
                logger.warn ("ipv4.getFlags(): "+ipv4.getFlags());

                if (ipv4.getProtocol().equals(IpProtocol.TCP)){
                    logger.warn ("TCP Packet Received!:-)");
                    TCP tcp = (TCP) ipv4.getPayload();
                    logger.warn ("tcp.getFlags"+tcp.getFlags());
                    logger.warn ("tcp.getDestinationPort: "+tcp.getDestinationPort());
                    logger.warn("tcp.getSourcePort: "+tcp.getSourcePort());
                    logger.warn("tcp.getSequence: "+tcp.getSequence());                 
         } 

         else if (eth.getEtherType() == EthType.IPv6) {
             logger.warn ("ARP-6 Packet Received!:-)");
         }

         else if (eth.getEtherType() == EthType.ARP) {

             logger.warn ("ARP Packet Received!:-)");
         }

         return Command.CONTINUE;
    }

当我在主机之间使用iperf时,Floodlight模块上的代码可以正常工作。但是,关于Scapy,当我在主机上运行第一个代码时,在接收任何TCP数据包的Floodlight输出中看不到任何结果。怎么了?

0 个答案:

没有答案