Code Sample |
#!/usr/bin/env flua -- (c) 2005 Richard Osborne -- Show IP current Address in a dialog box function get_ip_address(interface) local command="ifconfig " .. interface .. " > /tmp/pipe.lua &" execute(command) local file,err = openfile("/tmp/pipe.lua", "r") if not file then print("Cannot open file. ".. err) exit(1) end local data = read(file,"*a") local label = "inet addr:" local i,j = strfind (data,label .. "([%d.]*)") if not i then return("Not Configured") else return (strsub (data, i+strlen(label),j)) end end -- Main GUI loop w = Window{200,80, "IP Address"} ip = Input{40,10,120,25,"IP:"} ip.value = get_ip_address("eth0") ok = Button{65,45,70,25,"&OK"} function ok:callback() flush() exit(0) end w:end_layout() w:show() |
Code Sample |
#!/usr/bin/env flua -- (c) 2005 Richard Osborne -- Show IP current Address in a dialog box function get_ip_address(interface) local command="ifconfig " .. interface .. " > /tmp/pipe.lua &" execute(command) local file,err = openfile("/tmp/pipe.lua", "r") if not file then print("Cannot open file. ".. err) exit(1) end local data = read(file,"*a") local label = "inet addr:" local i,j = strfind (data,label .. "([%d.]*)") if not i then return("Not Configured") else return (strsub (data, i+strlen(label),j)) end end -- Main GUI loop w = Window{200,80, "IP Address"} ip = Input{40,10,120,25,"IP:"} ip.value = get_ip_address("eth0") od = Button{100,45,70,25,"&Again"} ok = Button{10,45,70,25,"&OK"} function ok:callback() flush() exit(0) end function od:callback() ip.value = get_ip_address("eth0") end w:end_layout() w:show() |