LogoIPCONFIG Docs

Get My IP API

Get your current public IP address (IPv4 and IPv6)

Overview

The Get My IP API provides a simple way to retrieve your current public IP address. It supports both IPv4 and IPv6 addresses and can detect your network's IP version priority.

Endpoints

IPv4 Only

GET https://4.ipconfig.com/

IPv6 Only

GET https://6.ipconfig.com/

Auto Detection (with Priority Info)

GET https://test.ipconfig.com/api/ip/myip

Features

  • Free Service: No API key required
  • IPv4 & IPv6 Support: Get both IPv4 and IPv6 addresses
  • Network Priority Detection: Determine if your network prioritizes IPv4 or IPv6
  • Fast Response: Optimized for speed with global CDN
  • No Rate Limits: Unlimited requests for basic usage

Usage Examples

# Get IPv4 address
curl https://4.ipconfig.com/

# Get IPv6 address
curl https://6.ipconfig.com/

# Get IP with priority detection
curl https://test.ipconfig.com/api/ip/myip
// Using fetch API
async function getMyIP() {
  try {
    // Get IPv4
    const ipv4Response = await fetch('https://4.ipconfig.com/');
    const ipv4 = await ipv4Response.text();

    // Get IPv6
    const ipv6Response = await fetch('https://6.ipconfig.com/');
    const ipv6 = await ipv6Response.text();

    // Get priority info
    const testResponse = await fetch('https://test.ipconfig.com/api/ip/myip');
    const testData = await testResponse.json();

    return {
      ipv4: ipv4.trim(),
      ipv6: ipv6.trim(),
      priority: testData.IPVersion || 'IPv4'
    };
  } catch (error) {
    console.error('Error fetching IP:', error);
    return null;
  }
}

// Usage
getMyIP().then(result => {
  if (result) {
    console.log('IPv4:', result.ipv4);
    console.log('IPv6:', result.ipv6);
    console.log('Network Priority:', result.priority);
  }
});
import requests
import json

def get_my_ip():
    """Get current public IP addresses and network priority"""

    result = {
        'ipv4': None,
        'ipv6': None,
        'priority': 'IPv4'
    }

    try:
        # Get IPv4 address
        ipv4_response = requests.get('https://4.ipconfig.com/', timeout=5)
        if ipv4_response.ok:
            result['ipv4'] = ipv4_response.text.strip()
    except:
        pass

    try:
        # Get IPv6 address
        ipv6_response = requests.get('https://6.ipconfig.com/', timeout=5)
        if ipv6_response.ok:
            result['ipv6'] = ipv6_response.text.strip()
    except:
        pass

    try:
        # Get network priority
        test_response = requests.get('https://test.ipconfig.com/api/ip/myip', timeout=5)
        if test_response.ok:
            test_data = test_response.json()
            result['priority'] = test_data.get('IPVersion', 'IPv4')
    except:
        pass

    return result

# Usage example
if __name__ == "__main__":
    ip_info = get_my_ip()
    print(f"IPv4: {ip_info['ipv4'] or 'Not Available'}")
    print(f"IPv6: {ip_info['ipv6'] or 'Not Available'}")
    print(f"Network Priority: {ip_info['priority']}")
package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "strings"
    "time"
)

type IPInfo struct {
    IPv4     string `json:"ipv4"`
    IPv6     string `json:"ipv6"`
    Priority string `json:"priority"`
}

type TestResponse struct {
    IPVersion string `json:"IPVersion"`
}

func getMyIP() (*IPInfo, error) {
    client := &http.Client{Timeout: 5 * time.Second}
    result := &IPInfo{Priority: "IPv4"}

    // Get IPv4
    if resp, err := client.Get("https://4.ipconfig.com/"); err == nil {
        defer resp.Body.Close()
        if body, err := io.ReadAll(resp.Body); err == nil {
            result.IPv4 = strings.TrimSpace(string(body))
        }
    }

    // Get IPv6
    if resp, err := client.Get("https://6.ipconfig.com/"); err == nil {
        defer resp.Body.Close()
        if body, err := io.ReadAll(resp.Body); err == nil {
            result.IPv6 = strings.TrimSpace(string(body))
        }
    }

    // Get priority
    if resp, err := client.Get("https://test.ipconfig.com/api/ip/myip"); err == nil {
        defer resp.Body.Close()
        if body, err := io.ReadAll(resp.Body); err == nil {
            var testResp TestResponse
            if json.Unmarshal(body, &testResp) == nil {
                result.Priority = testResp.IPVersion
            }
        }
    }

    return result, nil
}

func main() {
    ipInfo, err := getMyIP()
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }

    fmt.Printf("IPv4: %s\n", getValueOrDefault(ipInfo.IPv4, "Not Available"))
    fmt.Printf("IPv6: %s\n", getValueOrDefault(ipInfo.IPv6, "Not Available"))
    fmt.Printf("Network Priority: %s\n", ipInfo.Priority)
}

func getValueOrDefault(value, defaultValue string) string {
    if value == "" {
        return defaultValue
    }
    return value
}
<?php

function getMyIP() {
    $result = [
        'ipv4' => null,
        'ipv6' => null,
        'priority' => 'IPv4'
    ];

    // Get IPv4 address
    try {
        $ipv4 = @file_get_contents('https://4.ipconfig.com/');
        if ($ipv4 !== false) {
            $result['ipv4'] = trim($ipv4);
        }
    } catch (Exception $e) {
        // Ignore error
    }

    // Get IPv6 address
    try {
        $ipv6 = @file_get_contents('https://6.ipconfig.com/');
        if ($ipv6 !== false) {
            $result['ipv6'] = trim($ipv6);
        }
    } catch (Exception $e) {
        // Ignore error
    }

    // Get network priority
    try {
        $testResponse = @file_get_contents('https://test.ipconfig.com/api/ip/myip');
        if ($testResponse !== false) {
            $testData = json_decode($testResponse, true);
            if (isset($testData['IPVersion'])) {
                $result['priority'] = $testData['IPVersion'];
            }
        }
    } catch (Exception $e) {
        // Ignore error
    }

    return $result;
}

// Usage example
$ipInfo = getMyIP();
echo "IPv4: " . ($ipInfo['ipv4'] ?: 'Not Available') . "\n";
echo "IPv6: " . ($ipInfo['ipv6'] ?: 'Not Available') . "\n";
echo "Network Priority: " . $ipInfo['priority'] . "\n";

?>

Response Format

Simple Text Response (4.ipconfig.com, 6.ipconfig.com)

203.0.113.1

JSON Response (test.ipconfig.com/api/ip/myip)

{
  "result": true,
  "code": "querySuccess",
  "message": "Query Success",
  "IP": "150.171.28.10",
  "IPVersion": "IPv4"
}
{
  "result": true,
  "code": "querySuccess",
  "message": "Query Success",
  "IP": "2620:1ec:33:1::10",
  "IPVersion": "IPv6"
}

Error Handling

The service is designed to be highly available, but you should always implement proper error handling:

async function getIPWithErrorHandling() {
  try {
    const response = await fetch('https://4.ipconfig.com/', {
      signal: AbortSignal.timeout(5000) // 5 second timeout
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    return await response.text();
  } catch (error) {
    if (error.name === 'AbortError') {
      console.error('Request timed out');
    } else {
      console.error('Network error:', error.message);
    }
    return null;
  }
}

Use Cases

  • Network Diagnostics: Check your current public IP
  • Geolocation Services: Determine user's approximate location
  • Security Applications: Monitor IP changes
  • Development Testing: Test applications with different IP scenarios
  • VPN Detection: Verify VPN connection status

Best Practices

  1. Implement Timeouts: Always set reasonable timeouts (3-5 seconds)
  2. Handle Errors Gracefully: Network requests can fail
  3. Cache Results: Avoid unnecessary requests by caching IP for short periods
  4. Use Appropriate Endpoint: Choose IPv4, IPv6, or auto-detection based on your needs
  5. Respect Rate Limits: While there are no strict limits, avoid excessive requests