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: model.AutonomousSystem = ip_info.get_as(ip_address) 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))
async 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: await 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))
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import asyncio import ipaddress import pprint import socket import ipywidgets as widgets from netanalysis.ip import ip_info as ii from netanalysis.ip import model from netanalysis.tls import domain_ip_validator VALIDATOR = domain_ip_validator.DomainIpValidator() def create_ip_info_widget(ip_info: ii.IpInfoService): 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: