How do I find out what my external IP address is?

2019-01-21 12:48发布

My computers are sitting behind a router/firewall. How do I programmatically find out what my external IP address is. I can use http://www.whatsmyip.org/ for ad-hoc queries, but the TOS don't allow for automated checks.

Any ideas?

13条回答
Explosion°爆炸
2楼-- · 2019-01-21 13:21
curl ifconfig.me

or

curl ifconfig.me/ip

Incase you don't have curl installed,

wget ifconfig.me/ip 2>/dev/null && cat ip

Hope this helps.

查看更多
够拽才男人
3楼-- · 2019-01-21 13:22

If the router you are behind speak UPnP you could always use a UPnP library for whatever language you are developing in to query the router for its external ip.

查看更多
倾城 Initia
4楼-- · 2019-01-21 13:24

ifcfg.me allows Lookup via

nslookup
telnet
ftp
and http

even works with IPv6

查看更多
We Are One
5楼-- · 2019-01-21 13:24

Simple but not elegant for this use. I installed some security cameras and my cable provider - Wide Open West or WOWWAY wanted $10 a month to set up a static IP - EXTORTION for a DHCP reservation ... so, I created a VBS file with the following code to drop the result to dropbox and google drive ... have to delete the file for new one to sync though for some reason.

This runs on a PC at my home. My PC is set to resume on power outage and a task is scheduled to run this every day once (note if you have it run often, the site will block your requests).

Now I can get my IP address on the road and watch people steal my stuff :-)

get_html "http://ipecho.net/plain", "C:\Users\joe\Google Drive\IP.html"

get_html "http://ipecho.net/plain", "C:\Users\joe\Dropbox\IP.html"



sub get_html (up_http, down_http)

dim xmlhttp : set xmlhttp = createobject("msxml2.xmlhttp.3.0")

xmlhttp.open "get", up_http, false

xmlhttp.send

dim fso : set fso = createobject ("scripting.filesystemobject")

dim newfile : set newfile = fso.createtextfile(down_http, true)

newfile.write (xmlhttp.responseText)

newfile.close

set newfile = nothing
set xmlhttp = nothing

end sub
查看更多
Rolldiameter
6楼-- · 2019-01-21 13:25

http://ipecho.net/plain appears to be a workable alternative, as whatismyip.com now requires membership for their automated link. They very kindly appear to be offering this service for free, so please don't abuse it.

查看更多
混吃等死
7楼-- · 2019-01-21 13:27

If you have access to a webserver with modphp, you can roll your own:

<?php print $_SERVER['REMOTE_ADDR']; ?>

If you don't want that to get abused, you'll have to keep it secret or add request limits.

I've been using one on my server for years.

Explicitly:

Create a file called whatismyip.php in your public_html folder in your website. It can be called anything and be anywhere in your webroot.

Add the line above, and then query your server:

curl http://example.com/whatismyip.php

for example.

查看更多
登录 后发表回答