Powershell Code Example
A quick Powershell snippet to integrate into the FraudGuard.io API
This PowerShell script performs the following steps:
- Sets the FraudGuard.io API credentials (username and password).
- Defines the IP address to query.
- Constructs the API endpoint URL.
- Converts the credentials to Base64 format for basic authentication.
- Sets the Authorization header with the encoded credentials.
- Sends a GET request to the API endpoint using Invoke-WebRequest.
- Checks if the request was successful (status code 200) and prints the response content.
- Prints an error message if the request was unsuccessful.
$username = 'username'
$password = 'password'
# IP address to query
$ipAddress = '8.8.8.8'
# API endpoint
$apiUrl = "https://api.fraudguard.io/ip/$ipAddress"
# Convert credentials to base64
$pair = "$($username):$($password)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
# Set headers
$headers = @{
Authorization = $basicAuthValue
}
# Send GET request to the API
$response = Invoke-WebRequest -Uri $apiUrl -Headers $headers
# Check if the request was successful
if ($response.StatusCode -eq 200) {
$responseContent = $response.Content
Write-Output $responseContent
} else {
Write-Output "Error: $($response.StatusCode) - $($response.StatusDescription)"
}
Make sure to replace ‘username’ and ‘password’ with your actual API credentials.