Skip to Content

Scripting Example - IP Address

This example demonstrates how to make an HTTP request from an default rule. The example retrieves the server's public IP address and defaults a cell value.

Table Schema

Column Data Type Primary Key Auto-generate Nullable
IpAddress NVARCHAR(100) No No No

Script

#r "System.Net.Http"

using System;
using System.Net.Http;

var client = new HttpClient();

const string url = "https://api.ipify.org?format=text";

string ipAddress;

using (HttpResponseMessage response = await client.GetAsync(url))
{
    if (!response.IsSuccessStatusCode)
    {
        const string message = "Failed to get IP address.";
        throw new InvalidOperationException(message);
    }

    ipAddress = await response.Content.ReadAsStringAsync();
}

Row["IpAddress"].Value = ipAddress;