newOldUser
Group: Members
Posts: 241
Joined: Oct. 2004 |
|
Posted: July 14 2005,23:39 |
|
Friedgold, thank you. This is a neat little piece of code.
I was looking for something that would display my IP address at startup. I run this code from my .xinitrc and bingo, at start up it displays the IP address.
I have a problem on one of my older machines that causes this code to return a "Not Configured" error the first time that it's run. I don't think it's your code, I think it just takes the machine a little while to set the net. Because of this I've added an "Again" button the code. The Again button simple tries to get the IP address another time. On my trouble machine, the second time is always a charm.
Thanks again.
Code with Again button follows:
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()
|
-------------- ======== Note ========= The DSL Forum Search default is 'OR' If you search for "cat dog" you will get all "cat" posts and all "dog" posts. If you search for "cat AND dog" you will only find results that contain BOTH "cat" and "dog" Add '*' for wildcards, " cat* and dog* "
|