<commit_before>import httplib
import socket
from netaddr import IPNetwork

PORT_NUMBER = 5575

def getLocalIP():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(('8.8.8.8', 0))
    local_ip_address = s.getsockname()[0]
    return local_ip_address

def getLocalIPList():
    #TODO farlo funzionare anche se non ho il route a 8.8.8.8
    networkip = IPNetwork('192.168.1.0/24')
    iplist = []

    #TODO prendere e considerare la subnetmask
    #TODO per farlo bene, prendere il range tra base e broadcast e farsi il ciclo tra quelli

    baseIp = str(networkip)
    broadcastIp = str(networkip.broadcast)

    #TODO applicare le cose dette sopra, quindi questa cosa va tolta
    tempIp = baseIp[0:baseIp.rfind(".") + 1]

    for i in range(1, 255):
        iplist.append(tempIp + "%s" % i)

    return iplist

def scanLocalIPs(iplist):
    esplist = {}

    number = 0

    for ip in iplist:
        try:
            conn = httplib.HTTPConnection(ip, PORT_NUMBER, timeout=0.05)
            conn.request("GET", "/scanning/beacon")
            response = conn.getresponse()
            #print "GET REQUEST to %s response: %s" % (ip, response.read())
            response.read()
            esplist["esp%s" % number] = ip
            number += 1
        except:
            pass

    return esplist

def setESPMode(ip, mode):
    conn = httplib.HTTPConnection(ip, PORT_NUMBER)
    conn.request("GET", "/settings/set/mode/%s" % mode)
    response = conn.getresponse()
    print response.read()

listOfIPs = getLocalIPList()
esplist = scanLocalIPs(listOfIPs)

if "esp0" in esplist:
    setESPMode(esplist["esp0"], "ledhandler")

print esplist
<commit_msg>non so che ho fatto<commit_after>import httplib
import socket
from netaddr import IPNetwork

PORT_NUMBER = 5575

def getLocalIP():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(('8.8.8.8', 0))
    local_ip_address = s.getsockname()[0]
    return local_ip_address

def getLocalIPList():
    #TODO farlo funzionare anche se non ho il route a 8.8.8.8
    networkip = IPNetwork('192.168.1.0/24')
    iplist = []

    #TODO prendere e considerare la subnetmask
    #TODO per farlo bene, prendere il range tra base e broadcast e farsi il ciclo tra quelli

    baseIp = str(networkip)
    broadcastIp = str(networkip.broadcast)

    #TODO applicare le cose dette sopra, quindi questa cosa va tolta
    tempIp = baseIp[0:baseIp.rfind(".") + 1]

    for i in range(1, 255):
        iplist.append(tempIp + "%s" % i)

    return iplist

def scanLocalIPs(iplist):
    esplist = {}

    number = 0

    for ip in iplist:
        try:
            conn = httplib.HTTPConnection(ip, PORT_NUMBER, timeout=0.1)
            conn.request("GET", "/scanning/beacon")
            response = conn.getresponse()
            #print "GET REQUEST to %s response: %s" % (ip, response.read())
            response.read()
            esplist["esp%s" % number] = ip
            number += 1
        except:
            pass

    return esplist

def setESPMode(ip, mode):
    conn = httplib.HTTPConnection(ip, PORT_NUMBER)
    conn.request("GET", "/settings/set/mode/%s" % mode)
    response = conn.getresponse()
    print response.read()

listOfIPs = getLocalIPList()
esplist = scanLocalIPs(listOfIPs)

print esplist

if "esp0" in esplist:
    setESPMode(esplist["esp0"], "ledhandler")

print esplist

{'fraction_non_alphanumeric': 0.11289364230540701, 'fraction_numerical': 0.021687462863933454, 'mean_word_length': 2.766219239373602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '1419863', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1142, 'n_words': 306}