I want to create a simple web application to fetch IP address details when 
IP entered in the HTML page .since I am a beginner I unable to do it. help 
me

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/119b47a5-8c85-4902-a99a-d62477c5a082%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Title: Search
Enter Ip Address:
import json
import requests
import urllib.request
import urllib.parse
import cgi
import urllib
from OTXv2 import OTXv2
from OTXv2 import IndicatorTypes
import random


# thus you will get the key word entered in search text box in searchterm variable in python.
form = cgi.FieldStorage()
searchterm = form.getvalue('searchbox')


class Virustotals():
    # Asks for user input of an IP and converts to a string for passing to virustotal
    global ipaddress
    ipaddress = str(input('Enter an IP address to scan: \n'))

    def __init__(self):
        self.ipaddress = ipaddress

    def scan(self):
        # this code for url or ip scan
        url = 'https://www.virustotal.com/vtapi/v2/url/scan'
        params = {'apikey': 'ed5da42cc5088d63845a74207562cd8655e7c4c9b09ffb6b5e739317ac664ae8', 'resource': ipaddress}
        response = requests.post(url, data=params)
        json_scan = response.json()
        print("json_scan", json_scan)

        # this code is for the gettings reports
    def reports(self):
        url = 'https://www.virustotal.com/vtapi/v2/ip-address/report'
        parameters = {'apikey': 'ed5da42cc5088d63845a74207562cd8655e7c4c9b09ffb6b5e739317ac664ae8','ip': ipaddress}
        response = urllib.request.urlopen('%s?%s' % (url, urllib.parse.urlencode(parameters))).read()
        response_scan = json.loads(response)
        # response = requests.post('https://www.virustotal.com/vtapi/v2/url/report', params=params, headers=headers)
        # response_dict = response.json
        print("response_dict", response_scan)

        # harvest important info from JSON response
        positiveresults = 0
        totalresults = 0
        try:
            for x in response_scan.get("detected_referrer_samples"):
                positiveresults = positiveresults + x.get("positives")
                totalresults = totalresults + x.get("total")
        except Exception as error:
            # if no results found program throws a TypeError
            print("No results {}".format(error))

        # convert results to string for output formatting
        positiveresults = str(positiveresults)
        totalresults = str(totalresults)

        # print results
        print(positiveresults + '/' + totalresults + ' total AV detection ratio')


class Otx(Virustotals):
    def __init__(self):
        self.ipaddress = ipaddress

    def scan_otx(self):
        # Your API key
        key = '0f9b19c83d936456e271956d4b4ee9d2561889edd32c07deda1100836ad9eba8'
        otx = OTXv2(random.choice(key))
        # key = self.otxKeys.put('0f9b19c83d936456e271956d4b4ee9d2561889edd32c07deda1100836ad9eba8')
        section_details = otx.get_indicator_details_full(IndicatorTypes.IPv4, self.ipaddress)
        otxresult = json.dumps(section_details)
        print('otxresult', otxresult)
        # rep = otx.get_indicator_details_by_section(IndicatorTypes.IPv4, line , section='reputation')
        mal = otx.get_indicator_details_by_section(IndicatorTypes.IPv4, self.ipaddress, section='malware')
        # print('rep',rep)
        print("mal", mal)
        print(json.dumps(mal, sort_keys=True, indent=4))
        # otx = OTXv2(API_KEY, server=OTX_SERVER)


if __name__ == '__main__':
    d = Virustotals()
    d.scan()
    d.reports()
    o = Otx()
    o.scan_otx()

Reply via email to