Beispiel #1
0
def host(hosttype, apikey, format, host, server, index):
    """Host (ip or domain) information"""
    try:
        ns_con = netlas.Netlas(api_key=apikey, apibase=server)
        query_res = ns_con.host(host=host, hosttype=hosttype, index=index)
        print(dump_object(data=query_res, format=format))
    except APIError as ex:
        print(dump_object(ex))
Beispiel #2
0
def indices(apikey, server, format):
    """Get available data indices."""
    try:
        ns_con = netlas.Netlas(api_key=apikey, apibase=server)
        query_res = ns_con.indices()
        print(dump_object(data=query_res, format=format))
    except APIError as ex:
        print(dump_object(ex))
Beispiel #3
0
def profile(apikey, server, format):
    """Get user profile data."""
    try:
        ns_con = netlas.Netlas(api_key=apikey, apibase=server)
        query_res = ns_con.profile()
        print(dump_object(data=query_res, format=format))
    except APIError as ex:
        print(dump_object(ex))
Beispiel #4
0
def stat(apikey, querystring, server, format, indices):
    """Get statistics for query."""
    try:
        ns_con = netlas.Netlas(api_key=apikey, apibase=server)
        query_res = ns_con.stat(query=querystring, indices=indices)
        print(dump_object(data=query_res, format=format))
    except APIError as ex:
        print(dump_object(ex))
Beispiel #5
0
def count(datatype, apikey, querystring, server, format, indices):
    """Calculate count of query results."""
    try:
        ns_con = netlas.Netlas(api_key=apikey, apibase=server)
        query_res = ns_con.count(query=querystring,
                                 datatype=datatype,
                                 indices=indices)
        print(dump_object(data=query_res, format=format))
    except APIError as ex:
        print(dump_object(ex))
Beispiel #6
0
def query(datatype, apikey, format, querystring, server, indices, page):
    """Search query."""
    try:
        ns_con = netlas.Netlas(api_key=apikey, apibase=server)
        query_res = ns_con.query(query=querystring,
                                 datatype=datatype,
                                 page=page,
                                 indices=indices)
        print(dump_object(data=query_res, format=format))
    except APIError as ex:
        print(dump_object(ex))
Beispiel #7
0
def download(apikey, datatype, count, output_file, querystring, server,
             indices, fields, source_type):
    """Download data."""
    try:
        ns_con = netlas.Netlas(api_key=apikey, apibase=server)
        c_bytes: int = 0
        fields = list() if not fields else fields.split(",")
        for i, query_res in enumerate(
                ns_con.download(query=querystring,
                                datatype=datatype,
                                size=count,
                                indices=indices,
                                fields=fields,
                                source_type=source_type)):
            if i > 0:
                output_file.write(b'\n')
            output_file.write(query_res)
            c_bytes += len(query_res)
            print(f"{c_bytes} bytes has been written to {output_file.name}",
                  end="\r")
        print("\n")
    except APIError as ex:
        print(dump_object(ex))
Beispiel #8
0
 def setUp(self):
     self.netlas = netlas.Netlas(api_key=config['TEST_API_KEY'],
                                 apibase=config['TEST_API_SERVER'],
                                 debug=True)