我的狡猾的嗅探器不起作用?

时间:2017-06-20 14:57:03

标签: python python-3.x

我编写了一个程序,用于从迭代中的数据包中收集数据。直到几天前,它运作良好。 编辑:已解决。我把IP保存为常数,它覆盖了IP。

from scapy.all import * 
import requests
import socket



ROUND = 2
IP = 'localhost'
PORT = 80
SERVER_ADDRESS = (IP,PORT)








def get_packet_size(packet):
    return len(packet)


def find_port(packet,ip):

    if packet[IP].dst == ip:
        if TCP in packet:
            return packet[TCP].sport
        else:
            return packet[UDP].sport
    else:
        if UDP in packet:
            return packet[TCP].dport
        else:
            return packet[UDP].dport
def check_traffic(packet , ip):

    if packet[IP].dst == ip:
        return False
    else:
        return True
def find_country(packet, ip):
    request = "http://freegeoip.net/json/"+ip
    response = requests.get(request)
    real_response = response.text

    real_response = real_response.split(",")
    country_full = real_response[2]
    country_full = country_full.split(":")
    country = country_full[1]
    country = country[1:len(country) - 1]
    print(country)

    return str(country)


def find_ip(packet):
    name = socket.gethostname()
    ip_of_agent = socket.gethostbyname(name)

    if(packet[IP].dst != ip_of_agent):
        return packet[IP].dst
    else:
        return packet[IP].src

def work_on_packets(packets):
    packet_dic = {}
    #ip_dic = []
    i = 0 # num of packet in iteration.
    for packet in packets:

        print("\n")
        packet_ip = find_ip(packet)
        print(packet_ip)

        country = find_country(packet,packet_ip)
        print(country)

        is_coming_traffic = check_traffic(packet,packet_ip) # True if coming , False if outer traffic. 

        port = find_port(packet,packet_ip)
        print(port)

        packet_size = get_packet_size(packet)
        print(packet_size)

        packet_dic["Packet "+str(i)] = [packet_ip,country,is_coming_traffic,port,packet_size]
        i = i + 1

    #send_data(packet_dic)





def is_IP(packet):
    return ((UDP in packet or TCP in packet) and IP in packet)

def main():
    print("Starting sniff..")
    while(True):
        packets = sniff(lfilter = is_IP )
        work_on_packets(packets)



main()

但是现在它只是不起作用。输出总是这样,仅此而已:

WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
Starting sniff..

背后可能出现什么问题?任何帮助都很棒!

1 个答案:

答案 0 :(得分:0)

这只是一个警告,告诉您没有IPV6的默认路由,对于没有IPV6的系统来说是完全正常的。这不应该影响您的IPV4数据包程序。

以下是禁用它的方法

import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)