コード例 #1
0
ファイル: main.py プロジェクト: vgiotsas/multilateral
def send_query(outputfile, asn, lg, command, query_address=False):
    if command == "traceroute" or command.startswith("neighbor") or lg["http"]["prefix"] is False:
        # if IP prefix is given strip out the prefix length
        if isinstance(query_address, Iterable):
            if '/' in query_address:
                query_address = Helper.convertPrefixToAddress(address)

    # validate the ip address
    ipIsValid = Helper.validateIPNetwork(query_address)
    if ipIsValid or command.startswith("summary") or command == "regex" or (command == "neighbor" and lg["output"]["type"] == "alice"):
        http_func, prevq, query_url = set_query_arguments(lg, query_address, command, asn)
        q = lg["commands"][command]
        query_method = getattr(qh, http_func)
        lg_response = query_method(q, str(query_url), str(lg["http"]["referer"]), lg["http"]["type"])

        # print the_page
        q = lg["commands"][command]
        if lg["commands"][command]["lg_query_arg"] and len(lg["commands"][command]["lg_query_arg"]) > 0:
            q[lg["commands"][command]["lg_query_arg"]] = prevq

        # scrap the output
        command_output = scrap_html_oputput(lg, lg_response, asn)
        # write to file
        filename = outputfile
        filename = filename.replace(":", "-")
        if not command.startswith("summary"):
            Helper.saveToFile(filename, "#> " + str(query_address) + "\n", "a+", asn)
        Helper.saveToFile(filename, str(command_output), "a+", asn)
        filepath = Helper.saveToFile(filename, "\n-----------------------------------------------------\n\n", "a+", asn)
        time.sleep(15)
        return filepath
コード例 #2
0
ファイル: main.py プロジェクト: vgiotsas/multilateral
def sendQuery(outputfile, asn, lg, command, queryAddress=False):
    prevq = ""
    if command == "traceroute" or command == "neighbor" or lg["http"]["prefix"] == False:
        # if IP prefix is given strip out the prefix length
	#print queryAddress
	if isinstance(queryAddress, Iterable):
        	if '/' in queryAddress:
            		queryAddress = Helper.convertPrefixToAddress(address)
    # validate the ip address
    ipIsValid = Helper.validateIPNetwork(queryAddress)
    if ipIsValid or command == "summary" or command == "regex":
        q = lg["commands"][command]
        if lg["commands"][command]["lg_query_arg"] in q:
            prevq = q[lg["commands"][command]["lg_query_arg"]]

        if lg["http"]["rarg"] != 0:
            if not isinstance(q[lg["http"]["rarg"]], basestring):
                q[lg["http"]["rarg"]] = q[lg["http"]["rarg"]][0]

        # set the command argument
        if command != "summary":
            q[lg["commands"][command]["lg_query_arg"]] = q[lg["commands"][command]["lg_query_arg"]].replace("$", queryAddress);

        # send the http request
        the_page = qh.send_http_request(q, str(lg["http"]["url"]), str(lg["http"]["referer"]), lg["http"]["type"])
        #print the_page
        
        q[lg["commands"][command]["lg_query_arg"]] = prevq
        # scrape the output
        table = qh.parse_html(the_page, lg["html"])
        if lg["html"]["striphtml"] == True:
            table = qh.strip_tags(table)
       
        filename = outputfile
        filename = filename.replace(":", "-")
        if command != "summary":
            Helper.saveToFile(filename, "#> " + str(queryAddress) + "\n", "a+", asn)
        Helper.saveToFile(filename, str(table), "a+", asn)
        filepath = Helper.saveToFile(filename, "\n-----------------------------------------------------\n\n", "a+", asn)
        time.sleep(15)
        return filepath
コード例 #3
0
ファイル: main.py プロジェクト: CAIDA/multilateral
def sendQuery(outputfile, asn, lg, command, queryAddress=False):
    prevq = ""
    if command == "traceroute" or command == "neighbor" or lg["http"]["prefix"] == False:
        # if IP prefix is given strip out the prefix length
	#print queryAddress
	if isinstance(queryAddress, Iterable):
        	if '/' in queryAddress:
            		queryAddress = Helper.convertPrefixToAddress(address)
    # validate the ip address
    ipIsValid = Helper.validateIPNetwork(queryAddress)
    if ipIsValid or command == "summary" or command == "regex":
        q = lg["commands"][command]
        if lg["commands"][command]["lg_query_arg"] in q:
            prevq = q[lg["commands"][command]["lg_query_arg"]]

        if lg["http"]["rarg"] != 0:
            if not isinstance(q[lg["http"]["rarg"]], basestring):
                q[lg["http"]["rarg"]] = q[lg["http"]["rarg"]][0]

        # set the command argument
        if command != "summary":
            q[lg["commands"][command]["lg_query_arg"]] = q[lg["commands"][command]["lg_query_arg"]].replace("$", queryAddress);

        # send the http request
        the_page = qh.send_http_request(q, str(lg["http"]["url"]), str(lg["http"]["referer"]), lg["http"]["type"])
        #print the_page
        
        q[lg["commands"][command]["lg_query_arg"]] = prevq
        # scrape the output
        table = qh.parse_html(the_page, lg["html"])
        if lg["html"]["striphtml"] == True:
            table = qh.strip_tags(table)
       
        filename = outputfile
        filename = filename.replace(":", "-")
        if command != "summary":
            Helper.saveToFile(filename, "#> " + str(queryAddress) + "\n", "a+", asn)
        Helper.saveToFile(filename, str(table), "a+", asn)
        filepath = Helper.saveToFile(filename, "\n-----------------------------------------------------\n\n", "a+", asn)
        time.sleep(15)
        return filepath