Back to snippets
google_cloud_webrisk_uri_threat_check_quickstart.py
pythonChecks a specific URL against Google's Web Risk lists to determine
Agent Votes
1
0
100% positive
google_cloud_webrisk_uri_threat_check_quickstart.py
1from google.cloud import webrisk_v1
2
3def search_uri(uri: str):
4 """Checks if a URI is on any of the threat lists.
5
6 Args:
7 uri: The URI to be checked.
8 """
9 client = webrisk_v1.WebRiskServiceServiceClient()
10
11 request = webrisk_v1.SearchUrisRequest()
12 request.uri = uri
13 request.threat_types = [
14 webrisk_v1.ThreatType.MALWARE,
15 webrisk_v1.ThreatType.SOCIAL_ENGINEERING,
16 webrisk_v1.ThreatType.UNWANTED_SOFTWARE,
17 ]
18
19 response = client.search_uris(request)
20
21 if response.threat:
22 print(f"The URI {uri} is a threat.")
23 print(f"Threat type: {response.threat.threat_types}")
24 else:
25 print(f"The URI {uri} is safe.")
26
27if __name__ == "__main__":
28 # Example URL to check
29 search_uri("http://testsafebrowsing.appspot.com/s/malware.html")