Exemplo n.º 1
0
    def test_get_countries(self):

        # Legacy
        countries = get_countries(is_legacy_xml=True)
        self.assertIsInstance(countries, dict)
        self.assertEqual(countries['US'], 'United States')

        # CSV
        countries = get_countries(is_legacy_xml=False)
        self.assertIsInstance(countries, dict)
        self.assertEqual(countries['US'], 'United States')
Exemplo n.º 2
0
    def set(self,pagenum,kw):
        try:
            url = 'http://www.ebay.com/sch/i.html?_from=R40&_sacat=0&LH_Complete=1&LH_Sold=1&LH_ItemCondition=3&_nkw=' + kw + '&_pgn=' + str(pagenum) + '&_ipg=200&rt=nc&_dmd=1'
            if len(self.proxies) > 0:
                countries = get_countries()
                obj = IPWhois(self.proxies[0].split(':')[0])
                results = obj.lookup(False)

                if countries[results['nets'][0]['country']] == "United States":

                    if self.getfile(url,self.proxies[0],".ht") == "error":
                        print("Switching Proxy")
                        self.proxies.pop(0)
                        self.set(pagenum,kw)
                    else:
                        print(self.proxies[0])

                else:
                    print(countries[results['nets'][0]['country']])
                    print("Non-US IP " + self.proxies[0].split(':')[0]  + ": Switching Proxy")
                    self.proxies.pop(0)
                    self.set(pagenum,kw)

            else:
                print("No Proxies in Queue")


        except Exception as e:
            print(str(e))
Exemplo n.º 3
0
def moreinformation(request):

    temp = 1
    domain = ""
    try:
        if request.POST:
            urls = request.POST['url']
            domain = get_tld(urls)
            ipadress = socket.gethostbyname(domain)
            obj = IPWhois(ipadress)
            results = obj.lookup_rdap(depth=1)
            verify = ""
            asn1 = str(results['asn'])
            print asn1
            file1 = open(
                "/home/guni/projectname/secondproject/GeoIPASNum2.txt", "r")
            for line1 in file1:
                line = line1.split(",")
                print asn1
                if asn1 in line[2]:
                    verify = "TRUE"
                    break
                else:
                    #print line[2]
                    verify = "FALSH"

            countries = get_countries()
            country1 = countries[results['asn_country_code']]

            return render(
                request,
                "/home/guni/projectname/firstproject/templates/moreinformation.html",
                {
                    "url": urls,
                    "ip": ipadress,
                    "asn": results['asn'],
                    "verify": verify,
                    "code": results['asn_country_code'],
                    "Registration": results['asn_date'],
                    "country": country1,
                    "register1": results['asn_registry']
                })
    except Exception, e:
        str1 = str(e)
        return render(
            request,
            "/home/guni/projectname/firstproject/templates/sorry.html",
            {"wrong": str1})
Exemplo n.º 4
0
    def get_country_for_ip(self, dst_ip):
        try:
            import ipwhois
            from ipwhois.utils import get_countries
        except ImportError:
            print('The ipwhois library is not install. pip install ipwhois')
            return False
        countries = get_countries()
        desc = self.get_whois_data(dst_ip)

        try:
            country = countries[desc['asn_country_code']]
            self.whois_cache[dst_ip]['country_name'] = country
            self.whois_country_cache[dst_ip] = country
        except KeyError:
            try:
                country = desc['asn_country_code']
            except KeyError:
                country = 'Unknown'
        return country
Exemplo n.º 5
0
    def set(self,pagenum,fn,kw,callback_proxies=None,backup_proxylist=None):
        try:
            url = 'http://www.ebay.com/sch/i.html?_from=R40&_sacat=0&LH_Complete=1&LH_Sold=1&LH_ItemCondition=3&_nkw=' + kw + '&_pgn=' + str(pagenum) + '&_ipg=200&rt=nc&_dmd=1'
            if len(self.proxies) > 0:
                countries = get_countries()
                obj = IPWhois(self.proxies[0].split(':')[0])
                results = obj.lookup(False)

                if countries[results['nets'][0]['country']] == "United States":

                    if self.getfile(url,self.proxies[0],"-" + fn + ".ht") == "error":
                        print("Switching Proxy")
                        self.proxies.pop(0)
                        self.set(pagenum,fn,kw)
                    else:
                        print(self.proxies[0] + " -->> " + kw)
                        self.kw = kw.replace("+"," ")

                else:
                    print(countries[results['nets'][0]['country']])
                    print("Non-US IP " + self.proxies[0].split(':')[0]  + ": Switching Proxy")
                    self.proxies.pop(0)
                    self.set(pagenum,fn,kw)

            else:
                print("No Proxies in Queue")
                if callback_proxies:
                    templist = callback_proxies()
                    if isinstance(templist,list) == True:
                        self.proxies = templist
                    else:
                        print("Callback function error")
                        
                if backup_proxylist:
                    self.proxies = self.proxies + backup_proxylist


        except Exception as e:
            print(str(e))
Exemplo n.º 6
0
 def test_get_countries(self):
     self.assertIsInstance(get_countries(), dict)
Exemplo n.º 7
0
                                end_address=script_args.calculate_cidr[1])

        print(('{0}Found {1} CIDR blocks for ({2}, {3}){4}:\n{5}'.format(
            ANSI['green'] if script_args.colorize else '', len(result),
            script_args.calculate_cidr[0], script_args.calculate_cidr[1],
            ANSI['end'] if script_args.colorize else '', '\n'.join(result))))

    except Exception as e:

        print(('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e))))

elif script_args.get_countries:

    try:

        result = get_countries()

        print(('{0}Found {1} countries{2}:\n{3}'.format(
            ANSI['green'] if script_args.colorize else '', len(result),
            ANSI['end'] if script_args.colorize else '', '\n'.join([
                '{0}: {1}'.format(k, v)
                for k, v in (iter(OrderedDict(sorted(result.items())).items()))
            ]))))

    except Exception as e:

        print(('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e))))

elif script_args.get_country:

    try:
Exemplo n.º 8
0
                    'type': 'keyword'
                }
            }
        }
    ]
}

# Get the current working directory.
CUR_DIR = path.dirname(__file__)

# Load the geo json for mapping ISO country codes to lat/lon geo coords.
with io.open(str(CUR_DIR) + '/data/geo_coord.json', 'r') as data_file:
    GEO_COORD = json.load(data_file)

# Get the ISO country code mappings.
COUNTRIES = get_countries()

# Default: localhost:9200
es = elasticsearch.Elasticsearch(host=args.host[0], port=args.port)


def delete_index():

    try:

        # Delete existing entries
        es.indices.delete(index='ipwhois_base')

    except elasticsearch.exceptions.NotFoundError:

        pass
Exemplo n.º 9
0
            len(result),
            script_args.calculate_cidr[0],
            script_args.calculate_cidr[1],
            ANSI['end'] if script_args.colorize else '',
            '\n'.join(result)
        ))

    except Exception as e:

        print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))

elif script_args.get_countries:

    try:

        result = get_countries()

        print('{0}Found {1} countries{2}:\n{3}'.format(
            ANSI['green'] if script_args.colorize else '',
            len(result),
            ANSI['end'] if script_args.colorize else '',
            '\n'.join(['{0}: {1}'.format(k, v) for k, v in (
                OrderedDict(sorted(result.items())).iteritems())])
        ))

    except Exception as e:

        print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))

elif script_args.get_country:
Exemplo n.º 10
0
 def test_get_countries(self):
     countries = get_countries()
     self.assertIsInstance(countries, dict)
     self.assertEqual(countries['US'], 'United States')
Exemplo n.º 11
0
            'mapping': {
                'type': 'keyword'
            }
        }
    }]
}

# Get the current working directory.
CUR_DIR = path.dirname(__file__)

# Load the geo json for mapping ISO country codes to lat/lon geo coords.
with io.open(str(CUR_DIR) + '/data/geo_coord.json', 'r') as data_file:
    GEO_COORD = json.load(data_file)

# Get the ISO country code mappings.
COUNTRIES = get_countries()

# Default: localhost:9200
es = elasticsearch.Elasticsearch(host=args.host, port=args.port)


def delete_index():

    try:

        # Delete existing entries
        es.indices.delete(index='ipwhois')

    except elasticsearch.exceptions.NotFoundError:

        pass
Exemplo n.º 12
0
import requests
import socket
import time
import os
import datetime
from ipwhois import IPWhois
from urllib import request
from ipwhois.utils import get_countries
import tldextract
from ipwhois.utils import get_countries

from ipwhois.experimental import bulk_lookup_rdap
from ipwhois.hr import (HR_ASN, HR_ASN_ORIGIN, HR_RDAP_COMMON, HR_RDAP,
                        HR_WHOIS, HR_WHOIS_NIR)

countries = get_countries(is_legacy_xml=True)

# use chunk size 5
#c_size = 5

#Creating DataFrames
df = pd.read_csv('Labelled_DataSet.csv')

#Converting DomainType to numeric
mal_legit = {'malicious': 1, 'legitmate': 0}

#assign/map 0 where there is legitimate domain type and 1 where there is malicious domain type
df['DomainType'] = df['DomainType'].map(mal_legit)


def check_date_type(d):
Exemplo n.º 13
0
import time
import traceback
from ipwhois import IPWhois
import pprint

# for mappings  like CH to Switzerland
from ipwhois.utils import get_countries
countries = get_countries()

#define input file
input_file = 'ips.txt'

#read file and create a list
list_file = open(input_file)
iplist = list_file.readlines()
list_file.close()

ip_abuse = {}

for ip in iplist:
    try:
        ip = str(ip)
        ip_abuse[ip] = {'ISP': [], 'Country': [], 'abuse': [], 'emails': []}

        obj = IPWhois('{}'.format(ip.strip("\n")))
        result = obj.lookup_rdap(depth=1)

        #pprint.pprint(result)

        for r_object in result['objects']:
Exemplo n.º 14
0
 def test_get_countries(self):
     countries = get_countries()
     self.assertIsInstance(countries, dict)
     self.assertEqual(countries['US'], 'United States')
Exemplo n.º 15
0
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
"""

#!/usr/bin/env python

import ipwhois
from ipwhois.utils import get_countries
countries = get_countries()

def convert_string(info_string):
    
    outstr = str(info_string)
    outstr = outstr[0].upper() + outstr[1:]
    outstr = outstr.replace("_", " ")
    
    return outstr


def parse_totext(proxy):
     
    info_string = "\nIP: %s:%s\n" % (str(proxy[0]), str(proxy[1]))

    for k, v in proxy[2].items():