updated codebase to support count

This commit is contained in:
Benjamyn Love 2019-06-30 22:56:49 +10:00
parent d591991f03
commit 2106592146
761 changed files with 7962 additions and 6491 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
env/
.vscode/
testData.txt

View File

@ -1,4 +1,7 @@
#!/usr/bin/python3
# Benjamyn Love
# 2018/2019
# bip (Bulk IP lookup)
import dns.resolver
import ipwhois
@ -9,6 +12,13 @@ import warnings
ipList = []
def loadBlacklist():
with open('blacklist.txt') as handle:
blacklist = handle.readlines()
for i in range(len(blacklist)):
blacklist[i] = blacklist[i].strip()
return blacklist
def lookupIP(inData):
try:
with warnings.catch_warnings():
@ -26,30 +36,45 @@ def lookupIP(inData):
def parseIPS():
global countIncluded
with open("ips.txt", 'r') as f:
testdata = f.read()
ipData = f.read()
data = testdata.split('\n')
data = ipData.split('\n')
for ip in data:
ip = ip.strip()
ipAddr = ip.split()
if len(ipAddr) == 2:
countIncluded = True
ipList.append(ipAddr)
else:
pass
if len(ipAddr) == 0:
pass
else:
countIncluded = False
ipList.append(ipAddr)
blacklist = loadBlacklist()
parseIPS()
for ips in ipList:
# ccode = ipCheck(lookupIP(ips[1]))
ret = lookupIP(ips[1])
if countIncluded == True:
ret = lookupIP(ips[1])
reverseName = reversename.from_address(ips[1])
else:
ret = lookupIP(ips[0])
reverseName = reversename.from_address(ips[0])
if ret == None:
continue
cc = ret["asn_country_code"]
desc = ret["asn_description"]
if cc == "AU" or cc == "NZ" or cc == "US":
if cc in blacklist:
continue
reverseName = reversename.from_address(ips[1])
try:
ptr = str(dns.resolver.query(reverseName, "PTR")[0])
except dns.resolver.NoAnswer as E:
@ -58,12 +83,9 @@ for ips in ipList:
ptr = reverseName
except dns.resolver.NXDOMAIN as E:
ptr = reverseName
print("IP: {}\t\tCountry: {}\tDesc: {}\tPTR: {}\tCount: {}".format(ips[1], cc, desc, ptr, ips[0]))
if countIncluded == True:
print("IP: {}\t\tCountry: {}\tDesc: {}\tPTR: {}\tCount: {}".format(ips[1], cc, desc, ptr, ips[0]))
else:
print("IP: {}\t\tCountry: {}\tDesc: {}\tPTR: {}".format(ips[0], cc, desc, ptr))
# print(ipList[0])
# lookupIP("123.23.23.12")
##{'asn_registry': 'apnic', 'asn': '4134', 'asn_cidr': '220.174.0.0/16', 'asn_country_code': 'CN', 'asn_date': '2002-10-30', 'asn_description': 'CHINANET-BACKBONE No.31,Jin-rong Street, CN'}

13
bip.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
FILENAME=$PWD/ips.txt
INSTDIR=$PWD
source ./env/bin/activate
if [ -z "${EDITOR}" ]
then
nano $FILENAME
else
$EDITOR $FILENAME
fi
clear
python $INSTDIR/PyGeoIP.py #set to python3 that is in use on the system, usually python3 will suffice
rm -f $FILENAME

Binary file not shown.

20
env/bin/activate.csh vendored
View File

@ -2,30 +2,37 @@
# You cannot run it directly.
# Created by Davide Di Blasi <davidedb@gmail.com>.
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
set newline='\
'
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH:q" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT:q" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
# Unset irrelevant variables.
deactivate nondestructive
setenv VIRTUAL_ENV "/home/ben/Documents/Projects/Python/PyGeoIP/env"
set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
set _OLD_VIRTUAL_PATH="$PATH:q"
setenv PATH "$VIRTUAL_ENV:q/bin:$PATH:q"
if ("" != "") then
set env_name = ""
else
set env_name = `basename "$VIRTUAL_ENV"`
set env_name = "$VIRTUAL_ENV:t:q"
endif
# Could be in a non-interactive environment,
# in which case, $prompt is undefined and we wouldn't
# care about the prompt anyway.
if ( $?prompt ) then
set _OLD_VIRTUAL_PROMPT="$prompt"
set prompt = "[$env_name] $prompt"
set _OLD_VIRTUAL_PROMPT="$prompt:q"
if ( "$prompt:q" =~ *"$newline:q"* ) then
:
else
set prompt = "[$env_name:q] $prompt:q"
endif
endif
unset env_name
@ -33,4 +40,3 @@ unset env_name
alias pydoc python -m pydoc
rehash

View File

@ -1,4 +1,4 @@
# This file must be used using `. bin/activate.fish` *within a running fish ( http://fishshell.com ) session*.
# This file must be used using `source bin/activate.fish` *within a running fish ( http://fishshell.com ) session*.
# Do not run it directly.
function deactivate -d 'Exit virtualenv mode and return to the normal environment.'

View File

@ -9,19 +9,21 @@ try:
__file__
except NameError:
raise AssertionError(
"You must run this like execfile('path/to/activate_this.py', dict(__file__='path/to/activate_this.py'))")
import sys
"You must run this like execfile('path/to/activate_this.py', dict(__file__='path/to/activate_this.py'))"
)
import os
old_os_path = os.environ.get('PATH', '')
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + os.pathsep + old_os_path
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if sys.platform == 'win32':
site_packages = os.path.join(base, 'Lib', 'site-packages')
else:
site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
prev_sys_path = list(sys.path)
import site
import sys
old_os_path = os.environ.get("PATH", "")
os.environ["PATH"] = os.path.dirname(os.path.abspath(__file__)) + os.pathsep + old_os_path
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if sys.platform == "win32":
site_packages = os.path.join(base, "Lib", "site-packages")
else:
site_packages = os.path.join(base, "lib", "python%s" % sys.version[:3], "site-packages")
prev_sys_path = list(sys.path)
site.addsitedir(site_packages)
sys.real_prefix = sys.prefix
sys.prefix = base

View File

@ -1,4 +1,4 @@
# Copyright (c) 2013-2017 Philip Hane
# Copyright (c) 2013-2019 Philip Hane
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -482,10 +482,8 @@ class IPWhoisCLI:
if json_data is None:
json_data = {}
# Python 2.6 doesn't support set literal expressions, use explicit
# set() instead.
keys = set(['asn', 'asn_cidr', 'asn_country_code', 'asn_date',
'asn_registry', 'asn_description']).intersection(json_data)
keys = {'asn', 'asn_cidr', 'asn_country_code', 'asn_date',
'asn_registry', 'asn_description'}.intersection(json_data)
output = ''

View File

@ -1,4 +1,4 @@
# Copyright (c) 2013-2017 Philip Hane
# Copyright (c) 2013-2019 Philip Hane
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

BIN
env/bin/python vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,20 +1,21 @@
import imp
import os
import sys
import warnings
import imp
import opcode # opcode is not a virtualenv module, so we can use it to find the stdlib
# Important! To work on pypy, this must be a module that resides in the
# lib-python/modified-x.y.z directory
import warnings
# opcode is not a virtualenv module, so we can use it to find the stdlib
# Important! To work on pypy, this must be a module that resides in the
# lib-python/modified-x.y.z directory
import opcode
dirname = os.path.dirname
distutils_path = os.path.join(os.path.dirname(opcode.__file__), 'distutils')
distutils_path = os.path.join(os.path.dirname(opcode.__file__), "distutils")
if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
warnings.warn(
"The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
warnings.warn("The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
else:
__path__.insert(0, distutils_path)
real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ('', '', imp.PKG_DIRECTORY))
__path__.insert(0, distutils_path) # noqa: F821
real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ("", "", imp.PKG_DIRECTORY))
# Copy the relevant attributes
try:
__revision__ = real_distutils.__revision__
@ -22,80 +23,94 @@ else:
pass
__version__ = real_distutils.__version__
from distutils import dist, sysconfig
from distutils import dist, sysconfig # isort:skip
try:
basestring
except NameError:
basestring = str
## patch build_ext (distutils doesn't know how to get the libs directory
## path on windows - it hardcodes the paths around the patched sys.prefix)
# patch build_ext (distutils doesn't know how to get the libs directory
# path on windows - it hardcodes the paths around the patched sys.prefix)
if sys.platform == 'win32':
if sys.platform == "win32":
from distutils.command.build_ext import build_ext as old_build_ext
class build_ext(old_build_ext):
def finalize_options (self):
def finalize_options(self):
if self.library_dirs is None:
self.library_dirs = []
elif isinstance(self.library_dirs, basestring):
self.library_dirs = self.library_dirs.split(os.pathsep)
self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
old_build_ext.finalize_options(self)
from distutils.command import build_ext as build_ext_module
from distutils.command import build_ext as build_ext_module
build_ext_module.build_ext = build_ext
## distutils.dist patches:
# distutils.dist patches:
old_find_config_files = dist.Distribution.find_config_files
def find_config_files(self):
found = old_find_config_files(self)
system_distutils = os.path.join(distutils_path, 'distutils.cfg')
#if os.path.exists(system_distutils):
# found.insert(0, system_distutils)
# What to call the per-user config file
if os.name == 'posix':
if os.name == "posix":
user_filename = ".pydistutils.cfg"
else:
user_filename = "pydistutils.cfg"
user_filename = os.path.join(sys.prefix, user_filename)
if os.path.isfile(user_filename):
for item in list(found):
if item.endswith('pydistutils.cfg'):
if item.endswith("pydistutils.cfg"):
found.remove(item)
found.append(user_filename)
return found
dist.Distribution.find_config_files = find_config_files
## distutils.sysconfig patches:
# distutils.sysconfig patches:
old_get_python_inc = sysconfig.get_python_inc
def sysconfig_get_python_inc(plat_specific=0, prefix=None):
if prefix is None:
prefix = sys.real_prefix
return old_get_python_inc(plat_specific, prefix)
sysconfig_get_python_inc.__doc__ = old_get_python_inc.__doc__
sysconfig.get_python_inc = sysconfig_get_python_inc
old_get_python_lib = sysconfig.get_python_lib
def sysconfig_get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
if standard_lib and prefix is None:
prefix = sys.real_prefix
return old_get_python_lib(plat_specific, standard_lib, prefix)
sysconfig_get_python_lib.__doc__ = old_get_python_lib.__doc__
sysconfig.get_python_lib = sysconfig_get_python_lib
old_get_config_vars = sysconfig.get_config_vars
def sysconfig_get_config_vars(*args):
real_vars = old_get_config_vars(*args)
if sys.platform == 'win32':
if sys.platform == "win32":
lib_dir = os.path.join(sys.real_prefix, "libs")
if isinstance(real_vars, dict) and 'LIBDIR' not in real_vars:
real_vars['LIBDIR'] = lib_dir # asked for all
elif isinstance(real_vars, list) and 'LIBDIR' in args:
real_vars = real_vars + [lib_dir] # asked for list
if isinstance(real_vars, dict) and "LIBDIR" not in real_vars:
real_vars["LIBDIR"] = lib_dir # asked for all
elif isinstance(real_vars, list) and "LIBDIR" in args:
real_vars = real_vars + [lib_dir] # asked for list
return real_vars
sysconfig_get_config_vars.__doc__ = old_get_config_vars.__doc__
sysconfig.get_config_vars = sysconfig_get_config_vars

Some files were not shown because too many files have changed in this diff Show More