/// <summary> /// /// Documentation https://developers.google.com/safebrowsing/v4/reference/encodedFullHashes/get /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Safebrowsing service.</param> /// <param name="encodedRequest">A serialized FindFullHashesRequest proto.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>FindFullHashesResponseResponse</returns> public static FindFullHashesResponse Get(SafebrowsingService service, string encodedRequest, EncodedFullHashesGetOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (encodedRequest == null) { throw new ArgumentNullException(encodedRequest); } // Building the initial request. var request = service.EncodedFullHashes.Get(encodedRequest); // Applying optional parameters to the request. request = (EncodedFullHashesResource.GetRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request EncodedFullHashes.Get failed.", ex); } }
private async Task <string> CheckURL(string url) { Console.WriteLine($"Checking to following URL using the Google Safe Browsing API:\n{url}"); var service = new SafebrowsingService(new BaseClientService.Initializer { ApplicationName = "dotnet-client", ApiKey = _dataService.RSettings.ProgramSettings.GoogleSafeBrowsingAPI }); var request = service.ThreatMatches.Find(new GoogleSecuritySafebrowsingV4FindThreatMatchesRequest() { Client = new GoogleSecuritySafebrowsingV4ClientInfo { ClientId = "Dotnet-client", ClientVersion = "1.5.2" }, ThreatInfo = new GoogleSecuritySafebrowsingV4ThreatInfo() { ThreatTypes = new List <string> { "Malware", "Social_Engineering", "Unwanted_Software", "Potentially_Harmful_Application" }, PlatformTypes = new List <string> { "Any_Platform" }, ThreatEntryTypes = new List <string> { "URL" }, ThreatEntries = new List <GoogleSecuritySafebrowsingV4ThreatEntry> { new GoogleSecuritySafebrowsingV4ThreatEntry { Url = url } } } }); var response = await request.ExecuteAsync(); if (response.Matches != null) { //returns only first threat return(response.Matches[0].ThreatType); } service.Dispose(); return(null); }
/// <summary> /// Lists the Safe Browsing threat lists available for download. /// Documentation https://developers.google.com/safebrowsing/v4/reference/threatLists/list /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Safebrowsing service.</param> /// <returns>ListThreatListsResponseResponse</returns> public static ListThreatListsResponse List(SafebrowsingService service) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } // Make the request. return(service.ThreatLists.List().Execute()); } catch (Exception ex) { throw new Exception("Request ThreatLists.List failed.", ex); } }
/// <summary> /// Finds the threat entries that match the Safe Browsing lists. /// Documentation https://developers.google.com/safebrowsing/v4/reference/threatMatches/find /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Safebrowsing service.</param> /// <param name="body">A valid Safebrowsing v4 body.</param> /// <returns>FindThreatMatchesResponseResponse</returns> public static FindThreatMatchesResponse Find(SafebrowsingService service, FindThreatMatchesRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Make the request. return(service.ThreatMatches.Find(body).Execute()); } catch (Exception ex) { throw new Exception("Request ThreatMatches.Find failed.", ex); } }