Re: Where is this computer in the world?
- Posted by Thomas Nov 25, 2012
- 1177 views
ChrisB said...
Here's a very quick snippet to find out where this particular computer is in the internet world (linux only)
include std/io.e include std/filesys.e sequence ifile, thiscomp = {}, extaddr = {} system("/sbin/ifconfig > if.txt", 0) ifile = read_lines("if.txt") for i = 1 to length(ifile) do if match("inet addr:", ifile[i]) > 0 then thiscomp = "This computer " & ifile[i][match("inet addr:", ifile[i])..$] exit end if end for system("wget -q http://automation.whatismyip.com/n09230945.asp", 0) extaddr = read_lines("n09230945.asp") extaddr = "External ip = " & extaddr[1] puts(1, thiscomp & "\n") puts(1, extaddr & "\n") delete_file("wget.log") delete_file("n09230945.asp") delete_file("if.txt")
{{{ This one is less nix centric
}}
-- include std/regex.e include std/pipeio.e object z = pipeio:create() process p = pipeio:exec("curl http://checkip.dyndns.com/", z) object myip = pipeio:read(p[STDOUT], 256) pipeio:kill(p) -- http://checkip.dyndns.com/ -- sequence myip = "<html><head><title>Current IP Check</title></head><body>Current IP Address: 1.2.3.4</body></html>" object r = regex:new("\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b") sequence ip = regex:find(r, myip) puts(1, myip[ip[1][1]..ip[1][2]])