ipy.ch

Meine IP-Adresse

Meine öffentliche IP-Adresse lautet:

Klicken zum Kopieren

Alternative IP

Klicken zum Kopieren

Meine lokale IP-Adresse lautet:

Klicken zum Kopieren

Was ist ipy.ch?

Mit ipy.ch kannst du deine öffentliche IP-Adresse einfach und schnell über eine API abfragen...

Was genau ist eine IP-Adresse?

Eine IP-Adresse (Internet Protocol Address) ist eine exklusive Nummer, die von allen IT-Geräten wie Druckern, Routern und Modems genutzt wird...

IPv4 vs. IPv6

Warum gibt es zwei Versionen? IPv4 (z. B. 192.168.1.1) ist das ursprüngliche Protokoll...

API

Die API von ipy.ch ist sehr einfach zu benutzen...
API URL Antwort Typ Beispiel Output (IPv4) Beispiel Output (IPv6)
https://api.ipy.ch text 66.249.64.136 2a00:1450:400a:803::200e
https://api4.ipy.ch text 66.249.64.136 -
https://api6.ipy.ch text - 2a00:1450:400a:803::200e
https://api.ipy.ch?format=json json {"ip":"66.249.64.136"} {"ip":"2a00:1450:...:200e"}
https://api.ipy.ch?format=jsonp jsonp callback({"ip":"66.249..."}); callback({"ip":"2a00:..."});
https://api.ipy.ch?format=jsonp&callback=getip jsonp getip({"ip":"66.249..."}); getip({"ip":"2a00:..."});

Beispiele

Hier ein paar Code-Beispiele wie man die API in verschiedenen Programmiersprachen verwenden kann.

Bash

#!/bin/bash
ip=$(curl -s https://api.ipy.ch)
echo "__ECHO_TEXT__ $ip"

# Get IPv4 address
ip4=$(curl -4 -s https://api.ipy.ch)
echo "__ECHO_TEXT_V4__ $ip4"

# Get IPv6 address
ip6=$(curl -6 -s https://api.ipy.ch)
echo "__ECHO_TEXT_V6__ $ip6"

Python

# Dieses Beispiel braucht die requests library
from requests import get

ip = get('https://api.ipy.ch').text
print '__ECHO_TEXT__', ip

Javascript

<script type="application/javascript">
  function getIP(json) {
    document.write("__ECHO_TEXT__ ", json.ip);
  }
</script>
<script type="application/javascript" src="https://api.ipy.ch?format=jsonp&callback=getIP"></script>

NodeJS

var http = require('http');

http.get({'host': 'api.ipy.ch', 'port': 80, 'path': '/'}, function(resp) {
  resp.on('data', function(ip) {
    console.log("__ECHO_TEXT__ " + ip);
  });
});

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://api.ipy.ch"))
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println("__ECHO_TEXT__ " + response.body());
    }
}

C++

#include <iostream>
#include <string>
#include <curl/curl.h>

// Benötigt die libcurl Bibliothek
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main() {
    CURL *curl = curl_easy_init();
    std::string ip;
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.ipy.ch");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ip);
        curl_easy_perform(curl);
        curl_easy_cleanup(curl);

        std::cout << "__ECHO_TEXT__ " << ip << std::endl;
    }
    return 0;
}

C#

using System;
using System.Net;

namespace ipy.Examples {
    class Program {
        public static void Main (string[] args) {
            WebClient webClient = new WebClient();
            string publicIp = webClient.DownloadString("https://api.ipy.ch");
            Console.WriteLine("__ECHO_TEXT__ {0}", publicIp);
        }
    }
}

PHP

<?php
    $ip = file_get_contents('https://api.ipy.ch');
    echo "__ECHO_TEXT__ " . $ip;
?>

Go

package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    resp, err := http.Get("https://api.ipy.ch")
    if err == nil {
        defer resp.Body.Close()
        ip, _ := io.ReadAll(resp.Body)
        fmt.Printf("__ECHO_TEXT__ %s\n", ip)
    }
}

Rust

// Benötigt das 'reqwest' und 'tokio' crate
use reqwest;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let ip = reqwest::get("https://api.ipy.ch").await?.text().await?;
    println!("__ECHO_TEXT__ {}", ip);
    Ok(())
}

Kotlin

import java.net.URL

fun main() {
    val ip = URL("https://api.ipy.ch").readText()
    println("__ECHO_TEXT__ $ip")
}

Swift

import Foundation

if let url = URL(string: "https://api.ipy.ch") {
    do {
        let ip = try String(contentsOf: url, encoding: .utf8)
        print("__ECHO_TEXT__ \(ip)")
    } catch {
        print("Error: \(error)")
    }
}

Ruby

require "net/http"

ip = Net::HTTP.get(URI("https://api.ipy.ch"))
puts "__ECHO_TEXT__ " + ip

jQuery

<script type="application/javascript">
  $(function() {
    $.getJSON("https://api.ipy.ch?format=jsonp&callback=?",
      function(json) {
        document.write("__ECHO_TEXT__ ", json.ip);
      }
    );
  });
</script>

PowerShell

$ip = Invoke-WebRequest -Uri https://api.ipy.ch?format=json | ConvertFrom-Json
"__ECHO_TEXT__ {0}" -f $ip.ip

Perl

use strict;
use warnings;
use LWP::UserAgent;

my $ua = new LWP::UserAgent();
my $ip = $ua->get('https://api.ipy.ch')->content;
print '__ECHO_TEXT__ ' . $ip;

VB.NET

Dim client as New System.Net.WebClient
Dim ip as String = client.DownloadString("https://api.ipy.ch")
Console.WriteLine("__ECHO_TEXT__ {0}", ip)

Objective-C

NSURL *url = [NSURL URLWithString:@"https://api.ipy.ch"];
NSString *ipAddress = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(@"__ECHO_TEXT__ %@", ipAddress);

Öffentliche IP-Adresse

Die öffentliche IP-Adresse ist die digitale Identität deines Netzwerks im Internet. Man kann sie mit einer klassischen Postanschrift vergleichen: Damit Datenpakete (wie Webseiten oder E-Mails) den Weg zu dir finden, benötigt dein Anschluss eine weltweit eindeutige Adresse.

Die wichtigsten Fakten auf einen Blick:
  • Zuweisung: Dein Internetanbieter (ISP) weist deinem Router automatisch eine öffentliche IP zu.
  • Einzigartigkeit: Jede öffentliche Adresse existiert im globalen Netz zur selben Zeit nur ein einziges Mal.
  • Sichtbarkeit: Webserver sehen deine öffentliche IP, um zu wissen, wohin sie die angeforderten Informationen senden müssen.
  • Abgrenzung: Während alle Geräte bei dir zu Hause intern eigene (private) IP-Adressen haben, treten sie nach aussen hin alle gemeinsam unter derselben öffentlichen IP auf.
Ohne eine öffentliche IP-Adresse wäre eine Kommunikation mit Diensten ausserhalb deines eigenen Heimnetzwerks nicht möglich.

Öffentliche IP unter Windows (PowerShell) abfragen

PS C:\> (Invoke-WebRequest -Uri "https://api.ipy.ch").Content
66.249.64.136

Öffentliche IP unter macOS (Terminal) abfragen

$ curl -s https://api.ipy.ch
66.249.64.136

Öffentliche IP unter Linux (Terminal) abfragen

$ curl -s https://api.ipy.ch
66.249.64.136

Lokale IP-Adresse

Die lokale oder private IP-Adresse zeigt an mit welcher IP-Adresse du in deinem lokalen Netzwerk gefunden wirst. Diese Adresse wurde hier mit WebRTC ausgelesen. Diese Adressen sind Teil von den reservierten Adressbereichen. Diese privaten IP Informationen sollten eigentlich nicht ausserhalb deines lokalen Netzes zugänglich sein. Es ist aber bei Firefox, Chrome und zum Teil auch bei Opera möglich diese Informationen mit WebRTC auszulesen. Heise hat darüber berichtet.

Eure private IP findet ihr ganz einfach mit der Konsole heraus. Bei Windows mit ipconfig und bei unixoiden Systemen mit ifconfig.

Private IP unter Windows findet ihr beim Eintrag IPv4 Address

C:\ipconfig /all

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Transino(R) 1522R Gigabit Network Connection
   Physical Address. . . . . . . . . : FF-
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv6 Address. . . . . . . . . . . : 2002:(Preferred)
   Temporary IPv6 Address. . . . . . : 2002:(Preferred)
   Link-local IPv6 Address . . . . . : fe80::(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.0.2(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Sonntag, 11. Oktober 2035 19:08:00
   Lease Expires . . . . . . . . . . : Samstag, 24. Oktober 2035 08:21:43
   Default Gateway . . . . . . . . . : fe80::f
                                       192.168.0.1
   DHCP Server . . . . . . . . . . . : 192.168.0.1
   DHCPv6 IAID . . . . . . . . . . . : 1111111111
   DHCPv6 Client DUID. . . . . . . . : 00-00
   DNS Servers . . . . . . . . . . . : fe80::
                                       192.168.0.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Private IP unter macOS findet ihr ganz einfach mit folgendem Befehl

$ ipconfig getifaddr en0
66.249.64.136

Private IP unter Linux findet ihr beim Eintrag inet

$ ifconfig

eth0: flags=2344 UP,BROADCAST,RUNNING,MULTICAST  mtu 1500
        inet 192.168.0.3  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80:  prefixlen 0  scopeid 0x00
        ether 00:  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 0  memory 0x000000-f00000

To-Do

Hier ein kleiner Ausblick auf kommende Features und Verbesserungen:
  • GraphQL API Endpunkt hinzufügen
  • Mehr Anwendungsbeispiele
In die Zwischenablage kopiert!