<html> <p>Some common usage patterns from a variety of programming languages are outlined below.</p> <h3>Bash</h3> <pre class=„ language-bash“>#!/bin/bash ip=$(curl -s https://ip.seeip.org) echo „My public IP address is: $ip“ </pre> <h3>Python</h3> <pre class=„ language-python“># This example requires the requests library be installed. You can learn more # about the Requests library here: http://docs.python-requests.org/en/latest/ from requests import get ip = get('https://ip.seeip.org').text print('My public IP address is: {}'.format(ip)) </pre> <h3>Ruby</h3> <pre class=„ language-ruby“>require „net/http“ ip = Net::HTTP.get(URI(„https://ip.seeip.org“)) puts „My public IP Address is: “ + ip </pre> <h3>PHP</h3> <pre class=„ language-php“><?php
$ip = file_get_contents('https://ip.seeip.org');
echo "My public IP address is: " . $ip;
?> </pre> <h3>Java</h3> <pre class=„ language-java“>try (java.util.Scanner s = new java.util.Scanner(new java.net.URL(„https://ip.seeip.org“).openStream(), „UTF-8“).useDelimiter(„\\A“)) {
System.out.println("My current IP address is " + s.next());
} catch (java.io.IOException e) {
e.printStackTrace();
} </pre> <h3>Perl</h3> <pre class=„ language-perl“>use strict; use warnings; use LWP::UserAgent; my $ua = new LWP::UserAgent(); my $ip = $ua->get('https://ip.seeip.org')->content; print 'My public IP address is: '. $ip; </pre> <h3>C#</h3> <pre class=„ language-csharp“>var httpClient = new HttpClient(); var ip = await httpClient.GetStringAsync(„https://ip.seeip.org“); Console.WriteLine($„My public IP address is: {ip}“); </pre> <h3>VB.NET</h3> <pre class=„ language-csharp“>Dim httpClient As New System.Net.Http.HttpClient Dim ip As String = Await httpClient.GetStringAsync(„https://ip.seeip.org“) Console.WriteLine($„My public IP address is: {ip}“) </pre> <h3>NodeJS</h3> <pre class=„ language-javascript“>var http = require('http'); http.get({'host': 'ip.seeip.org', 'port': 80, 'path': '/'}, function(resp) {
resp.on('data', function(ip) {
console.log("My public IP address is: " + ip);
});
}); </pre> <h3>Go</h3> <pre class=„ language-go“>package main import (
"io/ioutil"
"net/http"
"os"
) func main() {
res, _ := http.Get("https://ip.seeip.org")
ip, _ := ioutil.ReadAll(res.Body)
os.Stdout.Write(ip)
} </pre> <h3>Racket</h3> <pre class=„language-scheme“>(require net/url) (define ip (port->string (get-pure-port (string->url „https://ip.seeip.org“)))) (printf „My public IP address is: ~a“ ip) </pre> <h3>Scala</h3> <pre class=„ language-scala“>val addr = scala.io.Source.fromURL(„https://ip.seeip.org“).mkString println(s„My public IP address is: $addr“) </pre> <h3>Javascript</h3> <pre class=„ language-javascript“><script type=„application/javascript“>
function getIP(json) {
document.write("My public IP address is: ", json.ip);
}
</script> <script type=„application/javascript“ src=„https://ip.seeip.org?format=jsonp&callback=getIP“></script> </pre> <h3>jQuery</h3> <pre class=„ language-javascript“><script type=„application/javascript“>
$(function() {
$.getJSON("https://ip.seeip.org?format=jsonp&callback=?",
function(json) {
document.write("My public IP address is: ", json.ip);
}
);
});
</script> </pre> <h3>C#</h3> <pre class=„ language-java“>using System; using System.Net; namespace seeip.Examples {
class Program {
public static void Main (string[] args) {
WebClient webClient = new WebClient();
string publicIp = webClient.DownloadString("https://ip.seeip.org");
Console.WriteLine("My public IP Address is: {0}", publicIp);
}
}
} </pre> <h3>nim</h3> <pre class=„language-nim“>import HttpClient var ip = newHttpClient().getContent(„https://ip.seeip.org“) echo(„My public IP address is: “, ip) </pre> <h3>PowerShell</h3> <pre class=„ language-powershell“>$ip = Invoke-RestMethod -Uri 'https://ip.seeip.org?format=json' „My public IP address is: $($ip.ip)“ </pre> <h3>Lua</h3> <pre class=„language-lua“>http.Fetch(„https://ip.seeip.org“, function(body) print(„My ip is: “ .. body ) end </pre> <h3>PureBasic</h3> <pre class=„language-basic“>InitNetwork() *Buffer = ReceiveHTTPMemory(„https://ip.seeip.org?format=json“) If *Buffer
ParseJSON(0, PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8)) FreeMemory(*Buffer) Debug GetJSONString(GetJSONMember(JSONValue(0), "ip"))
EndIf </pre> <h3>LiveCode</h3> <pre class=„language-ruby“>put „My public IP address is“ && url „https://ip.seeip.org“ </pre> <h3>LiveCode</h3> <pre class=„ language-ruby“>put „My public IP address is“ && url „https://ip.seeip.org“ </pre> <h3>Arduino</h3> <pre class=„ language-clike“>if (client.connect(„ip.seeip.org“, 80)) {
Serial.println("connected");
client.println("GET / HTTP/1.0");
client.println("Host: ip.seeip.org");
client.println();
} else {
Serial.println("connection failed");
} </pre> </html>