Beispiel #1
0
def getNearbyWeather():
    from geolocation import get_public_ip
    from geolocation import get_geolocation

    # get weather information by IP address
    my_ip = get_public_ip()
    print my_ip

    geo_info = get_geolocation(my_ip)
    print "get weather info @" + geo_info['city']

    observation_list = owm.weather_around_coords(geo_info['latitude'],
                                                 geo_info['longitude'])
    print len(observation_list)

    # XXX: avoid encoding error (see http://libsora.so/posts/python-hangul/)
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')

    returnList = []
    for observation in observation_list:
        w = observation.get_weather()
        location = observation.get_location()
        returnObj = {}
        returnObj[str(unicode(location.get_name()))] = w.get_detailed_status()
        returnList.append(returnObj)

    return returnList
Beispiel #2
0
def generate_suspicious_login_scenario2(df):
    global currentTime, usernames, ipAddressesForUsers, index
    username = usernames[random.randrange(NUMBER_OF_USERS)]
    currentTime = currentTime + datetime.timedelta(
        seconds=random.randrange(3000))
    ip = generate_random_ipv4()
    geo_loc = None
    while geo_loc is None:
        while ip in geoLocationForIP:
            ip = generate_random_ipv4()
        geo_loc = geolocation.get_geolocation(ip)
        if geo_loc.latitude == geoLocationForIP[ipAddressesForUsers[username]].latitude and geo_loc.longitude == \
                geoLocationForIP[ipAddressesForUsers[username]].longitude:
            geo_loc = None
            ip = generate_random_ipv4()
    geoLocationForIP[ip] = geo_loc
    generate_successful_login(df, currentTime, username)
    index = index + 1
    currentTime = currentTime + datetime.timedelta(
        seconds=random.randrange(60))
    generate_successful_login(df,
                              currentTime,
                              username,
                              ip,
                              is_suspicious=True)
    index = index + 1
Beispiel #3
0
def getNearbyWeather() :
    from geolocation import get_public_ip
    from geolocation import get_geolocation

    # get weather information by IP address
    my_ip = get_public_ip()
    print my_ip

    geo_info = get_geolocation(my_ip)
    print "get weather info @" + geo_info['city']

    observation_list = owm.weather_around_coords(geo_info['latitude'], geo_info['longitude'])
    print len(observation_list)

    # XXX: avoid encoding error (see http://libsora.so/posts/python-hangul/)
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')

    returnList = []
    for observation in observation_list :
        w = observation.get_weather()
        location = observation.get_location()
        returnObj = {}
        returnObj[str(unicode(location.get_name()))] = w.get_detailed_status()
        returnList.append(returnObj)

    return returnList
def parse_store(store):
    ret = {}
    for child in store.getchildren():
        if child.tag in IGNORE_LIST:
            continue
        tag = child.tag
        if tag in NAME_CONVERSION:
            tag = NAME_CONVERSION[tag]
        ret[tag] = child.text
    try:
        time.sleep(0.2)
        print ret['STOREID']
        geolocation = get_geolocation(('%s, %s' % (ret['ADDRESS'], ret['CITY'])).encode('utf8'))
        ret['Longtitude'] = geolocation[0]
        ret['Latitude'] = geolocation[1]
    except:
        pass
    return ret
Beispiel #5
0
def main():
    global currentTime, usernames, ipAddressesForUsers, geoLocationForIP, index, currentTime

    # generate usernames
    usernames = ['user' + str(x) for x in range(1, NUMBER_OF_USERS + 1)]

    # set current time
    currentTime = datetime.datetime.now()

    print("Generating IP addresses...")
    # generate an IP for each user
    for username in usernames:
        ipAddressesForUsers[username] = generate_random_ipv4()
        geoLocationForIP[
            ipAddressesForUsers[username]] = geolocation.get_geolocation(
                ipAddressesForUsers[username])

    login_data = pd.DataFrame(index=None, columns=LOGIN_TABLE_COLUMNS)
    index = 0
    iterations = ITERATIONS
    choices = [1, 2, 3, 4]
    p = [0.3, 0.3, 0.3, 0.1]
    print("Simulating user logins...")
    for i in range(iterations):
        c = np.random.choice(choices, p=p)
        if c == 1:
            generate_successful_login(login_data)
        elif c == 2:
            generate_failure_login(login_data)
        elif c == 3:
            generate_suspicious_login_scenario1(login_data)
        else:
            generate_suspicious_login_scenario2(login_data)
        print('Iteration ', i, ' of ', iterations, ' completed.')

    fileName = 'login_data-' + datetime.datetime.now().strftime(
        '%Y-%m-%d-%H-%M-%S') + '.csv'
    login_data.to_csv(fileName)
    print('Login data saved in \'' + fileName + '\'.')
Beispiel #6
0
 def set_geolocation(self, ip):
     self.ip = ip
     if ip not in geoLocationForIP:
         geoLocationForIP[ip] = geolocation.get_geolocation(ip)