<commit_before>import select as s
import random

from scapy.all import *
import pygeoip


def parse_stream(stream):
    ether_layer = stream.getlayer(Ether)
    IP_layer = stream.getlayer(IP)
    proto_layer = stream.getlayer(TCP)
    return ether_layer, IP_layer, proto_layer


def trace_route():
    # filter should be local IP addr
    streams = sniff(iface="en1", filter='tcp and src 10.1.56.83', count=10)
    for stream in streams:
        ether_layer, IP_layer, proto_layer = parse_stream(stream)
        destination = IP_layer.dst
        src = IP_layer.src
        dport = proto_layer.dport
        sport = proto_layer.sport

        while True:
            try:
                res, unans = traceroute(target=destination, dport=dport, sport=sport, maxttl=20)
                traces = res.res
                hops = [src]
                for trace in traces:
                    hops.append(trace[1].src)

                return hops, sport
            except s.error:
                continue


def map_ip(hops):
    gip = pygeoip.GeoIP('/Users/lynnroot/Dev/tissue/GeoLiteCity.dat')
    coordinates = []
    for hop in hops:
        geo_data = gip.record_by_addr(hop)
        if geo_data:
            lat = geo_data['latitude']
            lon = geo_data['longitude']
            coordinates.append((lon, lat))

    return coordinates
<commit_msg>get local ip addr instead of hardcode<commit_after>import select as s
import socket as sock

from scapy.all import *
import pygeoip


def parse_stream(stream):
    ether_layer = stream.getlayer(Ether)
    IP_layer = stream.getlayer(IP)
    proto_layer = stream.getlayer(TCP)
    return ether_layer, IP_layer, proto_layer

def get_local_ip():
    return sock.gethostbyname(socket.gethostname())

def trace_route():
    # filter should be local IP addr
    streams = sniff(iface="en1", filter='tcp and src %s' % get_local_ip(), count=10)
    for stream in streams:
        ether_layer, IP_layer, proto_layer = parse_stream(stream)
        destination = IP_layer.dst
        src = IP_layer.src
        dport = proto_layer.dport
        sport = proto_layer.sport

        while True:
            try:
                res, unans = traceroute(target=destination, dport=dport, sport=sport, maxttl=20)
                traces = res.res
                hops = [src]
                for trace in traces:
                    hops.append(trace[1].src)

                return hops, sport
            except s.error:
                continue


def map_ip(hops):
    gip = pygeoip.GeoIP('/Users/lynnroot/Dev/tissue/GeoLiteCity.dat')
    coordinates = []
    for hop in hops:
        geo_data = gip.record_by_addr(hop)
        if geo_data:
            lat = geo_data['latitude']
            lon = geo_data['longitude']
            coordinates.append((lon, lat))

    return coordinates

{'fraction_non_alphanumeric': 0.09055535903784931, 'fraction_numerical': 0.0067209055535903785, 'mean_word_length': 2.1704035874439462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4285017', 'n_tokens_mistral': 903, 'n_tokens_neox': 861, 'n_words': 211}