IP Validation API: Complete Developer Guide

Need to validate IP addresses in your application? This guide covers everything about IP validation via API, including IPv4 and IPv6 formats, validation rules, and implementation examples in multiple programming languages.

What is IP Validation?

IP validation verifies that a string is a properly formatted IP address. This includes checking the format, range of octets (for IPv4), and proper notation. Valid IP addresses are essential for network configurations and security.

Examples: 192.168.1.1 (IPv4), 2001:0db8:85a3:0000:0000:8a2e:0370:7334 (IPv6)

IP Address Formats

Understanding the two main IP address versions:

IPv4

32-bit address in dotted decimal notation. Four octets (0-255) separated by periods. Example: 192.168.0.1

IPv6

128-bit address in hexadecimal notation. Eight groups of four hex digits separated by colons. Example: 2001:db8::1

Note: Our API can also identify special IP ranges like private networks (10.x.x.x, 192.168.x.x), loopback (127.0.0.1), and broadcast addresses.

Using the IP Validation API

TinyFn provides a simple endpoint to validate IP addresses:

API Request
GET https://api.tinyfn.io/v1/validate/ip?ip=192.168.1.1
Headers: X-API-Key: your-api-key
Response
{
  "valid": true,
  "ip": "192.168.1.1",
  "version": 4,
  "type": "private",
  "is_loopback": false,
  "is_private": true,
  "is_public": false
}

Parameters

Parameter Type Description
ip string The IP address to validate (required)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/validate/ip?ip=192.168.1.1',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(result.valid); // true
console.log(result.version); // 4

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/validate/ip',
    params={'ip': '192.168.1.1'},
    headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['valid'])  # True
print(result['version'])  # 4

cURL

curl "https://api.tinyfn.io/v1/validate/ip?ip=192.168.1.1" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Form Validation: Validate IP addresses entered in configuration forms
  • Firewall Rules: Verify IP addresses before adding to allow/deny lists
  • Network Tools: Build network diagnostic tools with IP validation
  • Access Control: Validate IP addresses for whitelist/blacklist systems
  • Log Analysis: Verify IP addresses extracted from log files

Best Practices

  1. Support both versions: Handle both IPv4 and IPv6 in your applications
  2. Normalize input: Trim whitespace and handle common formatting issues
  3. Check address type: Distinguish between private, public, and special addresses
  4. Validate before use: Always validate IPs before using in network operations

Try the IP Validation API

Get your free API key and start validating IP addresses in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key