<commit_before>#!/usr/env/python
#
# Note: root is required to send ICMP packets
#
# Dependencies: 
#   netifaces (pip install netifaces) 

import sys
from netifaces import interfaces, ifaddresses, AF_INET
from scapy.all import send, ICMP, IP 

def get_base_addresses(): 
    base_addresses = []
    for iface in interfaces(): 
    # netifaces.interfaces() returns a list of the system's network interfaces
        inet_info = {}
        if AF_INET in ifaddresses(iface):
            inet_info = ifaddresses(iface)[AF_INET][0]
            # ifaddresses(i...INET] is a single-entry list, containing a 
            # dictionary. If the interface is not being used, the dict will 
            # be empty. 
            # When ifaddresses(i...INET][0] is not empty, it contains  
            # broadcast, netmask, addr
        if 'broadcast' in inet_info:
            base_addresses.append(inet_info['addr'])
            # loopback does not have a 'broadcast' entry, so this appears to 
            # be an acceptable way to include only non-lo interfaces. 
    return base_addresses


# Next: Define sequencing
# input is list of base addresses; from each base address, strip last octet; 
# for each address in [first-three-octets].0/24, icmp_echo()

# Next: Define icmp echo function

base_addresses = get_base_addresses()
print base_addresses

try: 
    send(IP(dst="172.16.8.1")/ICMP()) # Useless, just a test. Requires root.
except Exception, the_exception: 
    print the_exception<commit_msg>learning to use sr1() (scapy)<commit_after>#!/usr/env/python
#
# Note: root is required to send ICMP packets
#
# Dependencies: 
#   netifaces (pip install netifaces) 

import sys
from netifaces import interfaces, ifaddresses, AF_INET
from scapy.all import sr1, ICMP, IP 

def get_base_addresses(): 
    base_addresses = []
    for iface in interfaces(): 
    # netifaces.interfaces() returns a list of the system's network interfaces
        inet_info = {}
        if AF_INET in ifaddresses(iface):
            inet_info = ifaddresses(iface)[AF_INET][0]
            # ifaddresses(i...INET] is a single-entry list, containing a 
            # dictionary. If the interface is not being used, the dict will 
            # be empty. 
            # When ifaddresses(i...INET][0] is not empty, it contains  
            # broadcast, netmask, addr
        if 'broadcast' in inet_info:
            base_addresses.append(inet_info['addr'])
            # loopback does not have a 'broadcast' entry, so this appears to 
            # be an acceptable way to include only non-lo interfaces. 
    return base_addresses


# Next: Define sequencing
# input is list of base addresses; from each base address, strip last octet; 
# for each address in [first-three-octets].0/24, icmp_echo()

# Next: Define icmp echo function

base_addresses = get_base_addresses()
print base_addresses

try: 
    ping = sr1(IP(dst="192.168.1.2")/ICMP()/"X", timeout = 0.2) # Useless, just a test. Requires root.
    ping.show()
except Exception, the_exception: 
    print the_exception
{'fraction_non_alphanumeric': 0.09129720853858785, 'fraction_numerical': 0.009852216748768473, 'mean_word_length': 2.895140664961637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1935009', 'n_tokens_mistral': 974, 'n_tokens_neox': 918, 'n_words': 311}