Esempio n. 1
0
def get_ips(jsondata):
    """Uses the IPFlow data from the jsondata to gather IPs found in the traffic
        and performs a reverse lookup to find the origin country. The country is
        then added to a hashmap and the occurrences are recorded for a bar graph.
        Graph_geoIP() is then called and passed the observed countries in the
        x_axis and the occurrences as the y_axis.

        jsondata - The loaded data as parsed by parse.py containing statistics
            and information for graphing visuals.
    """
    ips = jsondata['Statistics']['IPflow']
    ip_mapping = dict()
    mapping_occurrence = dict()

    for ip in ips:
        source, dest = ip.split(' ')
        source_c = geocoder.maxmind(source)
        dest_c = geocoder.maxmind(dest)
        dest_country = dest_c.country
        source_country = source_c.country
        if source_country in mapping_occurrence.keys():
            mapping_occurrence[source_country] += 1
        else:
            mapping_occurrence[source_country] = 1
        if dest_country in mapping_occurrence.keys():
            mapping_occurrence[dest_country] += 1
        else:
            mapping_occurrence[dest_country] = 1
    country_x_axis = list()
    country_y_axis = list()
    for key in mapping_occurrence.keys():
        country_x_axis.append(key)
        country_y_axis.append(mapping_occurrence[key])
    graph_geoIP(country_x_axis, country_y_axis)
Esempio n. 2
0
def get_loc(sel):
    r = geocoder.maxmind('me').json
    if sel == 0:
        print("Your current location is : " + r['address'])
        return r['city']
    else:
        return r['country']
Esempio n. 3
0
def websitelocate():

    try:
        host = raw_input("Enter your website:")
        num = socket.gethostbyname(host)
        localisation = geocoder.maxmind(num)
        i = localisation.json
        for key, value in i.items():
            print key, ":", value
    except socket.gaierror:

        print("\nwebsite format unknow!, please try again...")
Esempio n. 4
0
def index():

    if request.method == 'POST':  #utilisation de la methode POST pour validation.

        msg = request.form[
            'valeur']  #la variable msg prend comme valeur l'url rentré

        ip4 = socket.gethostbyname(msg)  #affichage de l'ipv4

        sta = geocoder.maxmind(
            ip4)  #la variable sta prend comme valeur l'url rentré
        sta1 = sta.json

        asn1 = IPDetailsCache()  #instanciation de la classe IPDetailsCache()
        asn1_1 = asn1.GetIPInformation(
            ip4)  #utilisation de la methode GetIPInformation()

        wh = IPWhois(str(ip4))  #utilisation de la methode GetIPInformation()
        wh1 = wh.lookup_whois(
            get_referral=True)  #utilisation de la methode GetIPInformation()

        son_r = msg.replace('www.', '')
        repnse = dns.resolver.query(
            son_r, 'MX'
        )  #on obtient tout les serveurs de messagerie possible de notre domaine
        contenu = dns.resolver.query(
            son_r,
            'NS')  #on obtient tout les serveurs DNS possible de notre domaine

        url = urllib2.urlopen(
            "http://{0}".format(son_r)
        )  #on ouvre notre url grace a la methode urlopen du module urllib2
        url_result = dict(
            url.info()
        )  #recuperation de toute les reponse HTTP possible sur en provenance du serveur

        dat_a = google(str(msg))
        carto = Map(location=[dat_a.lat, dat_a.lng], zoom_start=15)
        Marker([dat_a.lat, dat_a.lng], popup=str(msg)).add_to(carto)
        carto.save('templates/cartographie.html')

        return render_template('resultat.html',
                               ip4=ip4,
                               msg=msg,
                               sta1=sta1,
                               asn1_1=asn1_1,
                               wh1=wh1,
                               repnse=repnse,
                               contenu=contenu,
                               url_result=url_result)

    return render_template("acceuil.html")  #affichage de la page d'acceuil
Esempio n. 5
0
def getgeo_maxmind(ip_list):
    count=1
    latlng_set=[]
    for ip in ip_list:
        geoinfo = geocoder.maxmind(ip)
        print("[maxmind] {} ({}/{}) country: {}".format(ip, count, len(ip_list), geoinfo.json.get('country')))
        if geoinfo.latlng:
            latlng_set.append([ip, geoinfo.latlng[0], geoinfo.latlng[1]])
        else:
            print("{} not found".format(ip))
            latlng_set.append([ip, "","" ])
        count = count + 1
    #print(latlng_set)
    return latlng_set 
Esempio n. 6
0
def getgeo_maxmind(ip_list):
    count = 1
    latlng_set = []
    for ip in ip_list:
        geoinfo = geocoder.maxmind(ip)
        print("[maxmind] {} ({}/{}) country: {}".format(
            ip, count, len(ip_list), geoinfo.json.get('country')))
        if geoinfo.latlng:
            latlng_set.append([ip, geoinfo.latlng[0], geoinfo.latlng[1]])
        else:
            print("{} not found".format(ip))
            latlng_set.append([ip, "", ""])
        count = count + 1
    #print(latlng_set)
    return latlng_set
Esempio n. 7
0
def data_ip():
    try:
        ip = donnee.get()
        name = socket.gethostbyname(ip) #convertir le site web en une adresse ip de type x.x.x.x

        i = geocoder.maxmind(name) #utilisation de package "maxmind" du module geocoder afin de geolocaliser
        a = i.json                 #l'hebergement du site web
        for b, c in a.items():
            texte.insert('1.0',(b, ":",c,'\n'))

        cache = IPDetailsCache()  # appel de la classe 'IPDetailsCache()'
        r = cache.GetIPInformation(name)  #utilisation de la methode 'GetIPInformation() pour obtenir l'ASN
        for cle, vals in r.items():  # select the items methods for show 'cle and valeur' values in boucle
            texte.insert('end',(cle, ":",vals,'\n'))

        reponse = dns.resolver.query(ip, 'MX')  # the variable 'reponse' contains the value MX of dns server
        for rdata in reponse:
            texte.insert('end',("seveurs mails:",rdata.exchange,'\n'))

        contenu = dns.resolver.query(ip, 'NS')  # the variable 'contenu' contains the value NS of dns server
        for resultat in contenu:
            texte.insert('end',("seveurs DNS:", resultat,'\n'))  # affiche tout les serveurs DNS

        command = "whois" + " " + ip
        process = os.popen(command)  # appel d'un commande systeme "popen" ppur executer la commande au dessus
        results = str(process.read())  # convertion du resultat en chaine de caractere et stockage dans une variable
        texte.insert('end', (results), '\n')

        command1 = "dnsmap" + " " + ip
        process1 = os.popen(command1)  # appel d'un commande systeme "popen" ppur executer la commande au dessus
        results1 = str(process1.read())  # convertion du resultat en chaine de caractere et stockage dans une variable
        texte.insert('end',(results1),'\n')

        tkMessageBox.showinfo('Resultat', 'Scan terminé')

    except socket.gaierror:
        return ("Address Unknown or Connection failed, tip on reset and put a good domain name")# msg a affiche quand le nom de domaine n'est pas connue
Esempio n. 8
0
db_geocoder = client.geocoder[provider]

# Store values in memory 
container = []
for item in db_ottawa.permits.distinct('location'):
    container.append(item)

container_geocoder = {}
for item in db_geocoder.find({}, {'properties.location':1}):
    container_geocoder[item['properties'].get('location')] = True

# Print Results
print 'Provider:',provider
print 'Permits:', len(container)
print 'Geocoded:', len(container_geocoder)
ip = geocoder.maxmind().ip

# Loop inside all permits
for item in container:
    location = item

    if location:
        # Only find ones that don't exist in Geocoder DB
        if not location in container_geocoder:
            if provider == 'ottawa':
                previous_location = location
                location = location.replace(', Ottawa, ON', '')
            # Geocode address
            g = geocoder.get(location, provider=provider, timeout=15.0)
            result = g.geojson
            
Esempio n. 9
0
def test_maxmind():
    g = geocoder.maxmind(ip)
    assert g.ok
Esempio n. 10
0
def test_maxmind():
    g = geocoder.maxmind(ip)
    assert g.ok
Esempio n. 11
0
def test_maxmind():
    g = geocoder.maxmind(location)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count >= 1
    assert fields_count >= 13
Esempio n. 12
0
db_geocoder = client.geocoder[provider]

# Store values in memory
container = []
for item in db_ottawa.permits.distinct('location'):
    container.append(item)

container_geocoder = {}
for item in db_geocoder.find({}, {'properties.location': 1}):
    container_geocoder[item['properties'].get('location')] = True

# Print Results
print 'Provider:', provider
print 'Permits:', len(container)
print 'Geocoded:', len(container_geocoder)
ip = geocoder.maxmind().ip

# Loop inside all permits
for item in container:
    location = item

    if location:
        # Only find ones that don't exist in Geocoder DB
        if not location in container_geocoder:
            if provider == 'ottawa':
                previous_location = location
                location = location.replace(', Ottawa, ON', '')
            # Geocode address
            g = geocoder.get(location, provider=provider, timeout=15.0)
            result = g.geojson