This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Automatic Ethernet connection checking and informing in case of troubles ?
#2
You can check some network futures yourself with the script below and do with it whatever you like. Run it as an init scrit and send an email with this information for example.
Have fun with it  Smile

require('json')
require('socket.http')

ip = io.readproc('if-json')
ip = json.decode(ip)
log("IP address: " ..ip.eth0.inetaddr)

socket.http.timeout = 5
data = socket.http.request('http://ip-api.com/json')
if data then
  data = json.decode(data)
  log("WAN IP: "..data.query)
  log("City: "..data.city)
  log("Region: "..data.region)
  log("Country: "..data.countryCode)
  log("Latitude: "..data.lat)
  log("Longitude: "..data.lon)
else
  log("There is possible no internet connection")
end

log("DNS name: " ..socket.dns.gethostname())

io.input("/sys/class/net/eth0/carrier")
carrier = io.read("*line")
if carrier == "1" then
  log("Connected to the network")
else
  log("No connection to the network")
end

io.input("/sys/class/net/eth0/operstate")
state = io.read("*line")
if state == "up" then
  log("The network connection is active")
else
  log("The network connection is inactive")
end
Reply


Messages In This Thread
RE: Automatic Ethernet connection checking and informing in case of troubles ? - by Joep - 05.11.2019, 15:18

Forum Jump: