예제 #1
0
def main(args):
    ip_info = create_default_ip_info_service()

    ip_address = args.ip_address[0]
    print("Country:  %s (%s)" % ip_info.get_country(ip_address))
    asys = ip_info.get_as(ip_address)  # type: model.AutonomousSytem
    print("ASN:  %d (%s)" % (asys.id, asys.name))
    # AS Type is is experimental and outdated data.
    print("Type: %s" % asys.type.name)
    print("Org:  %s (country: %s, name: %s)" %
          (asys.org.id, asys.org.country, asys.org.name))
    if ip_address.is_global:
        hostname = ip_info.resolve_ip(ip_address)
        if hostname:
            print("Hostname: %s" % hostname)
    else:
        print("IP in not global")
    validator = domain_ip_validator.DomainIpValidator()
    try:
        cert = asyncio.get_event_loop().run_until_complete(
            validator.get_cert(None, ip_address))
        if cert:
            print("TLS Certificate:\n%s" %
                  pprint.pformat(cert, width=100, compact=True))
    except Exception as e:
        print("TLS Certificate: %s" % repr(e))
예제 #2
0
 def tls_verify_unknowns(self):
     validator = domain_ip_validator.DomainIpValidator()
     # Try short domains first: they usually validate CNAMES, which tend to be longer.
     for domain, target in sorted(self.classifier.class_graph.edges(), key=lambda e: (len(e[0]), e[1])):
         if self.classifier.get_class(domain, target) != dc.EdgeClass.UNKNOWN:
             continue
         try:
             ipaddress.ip_network(target)
         except (ipaddress.AddressValueError, ValueError):
             continue
         net = target
         print("Checking IPs for {} - {}".format(domain, net))
         for ip in list(self.get_ips(net))[:2]:
             print("    Validating {}: ".format(ip), end="")
             try:
                 asyncio.get_event_loop().run_until_complete(validator.validate_ip(domain, ip))
                 print("VALID")
                 self.classifier.add_good_edge(
                     domain, net, "Pass TLS validation")
                 break
             except Exception as e:
                 print(_truncate(repr(e), 200))
예제 #3
0
import ipywidgets as widgets

from netanalysis.dns import domain_ip_validator
import netanalysis.model.autonomous_system as model

# TODO: Remove duplication with ip_info.py


def resolve_ip(ip) -> str:
    try:
        return socket.gethostbyaddr(ip.compressed)[0]
    except socket.herror:
        return None


VALIDATOR = domain_ip_validator.DomainIpValidator()


def create_ip_info_widget(as_repo):
    ip_field = widgets.Text(placeholder="Enter ip address", description="IP")
    get_btn = widgets.Button(description="Get info")
    output = widgets.Output()

    def show_ip_info(_):
        output.clear_output()
        if not ip_field.value:
            return
        try:
            ip_address = ipaddress.ip_address(ip_field.value)
        except ValueError as e:
            with output: