Re: ./EuGTK/GtkEngine.e to Irv
- Posted by irv Apr 24, 2015
- 1720 views
I've experimented with the following to avoid ifconfig: it detects if you are on a network, but cannot detect if there is internet available. I thought it would be easy to just ping google.com, but my 4g connection blocks pings! Anyone else have any ideas?
-------------------------------- export function inet_address() -------------------------------- object ip ifdef LINUX then sequence tmp = temp_file(,"MYIP-") if system_exec(sprintf("hostname -I > %s ",{tmp})) = 0 then ip = read_lines(tmp) if equal({""},ip) then if system_exec(sprintf("hostname -i > %s ",{tmp})) = 0 then ip = read_lines(tmp) if equal({""},ip) then return 0 else return ip[1] end if end if else return ip[1] end if end if end ifdef return 0 end function --------------------------------- export function networked() --------------------------------- ifdef NET then display("Localhost: [] My IP []",{localhost,inet_address()}) end ifdef return match("127.0",inet_address()) != 1 end function