Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Show IP Address, my first lua script :)< Next Oldest | Next Newest >
friedgold Offline





Group: Members
Posts: 122
Joined: Mar. 2005
Posted: July 01 2005,21:29 QUOTE

When DSL's network settings are obtained via DHCP the current IP Address is often unknown. Knowing the IP Address is necessary when connecting to the ssh server/ftp server/monkey webserver which come with DSL.

I put together this short lua-fltk script to display the current IP Address of the network device eth0. When run it pops up with a dialog box containing the current IP address and a 'ok' button to dismiss it. I then added it to the fluxbox menu (under System,Net Setup). I thought I'd post it here in the hope people find it useful.

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()
Back to top
Profile PM 
ico2 Offline





Group: Members
Posts: 802
Joined: July 2004
Posted: July 02 2005,16:20 QUOTE

cool

--------------
ico2
Back to top
Profile PM MSN 
cbagger01 Offline





Group: Members
Posts: 4264
Joined: Oct. 2003
Posted: July 02 2005,19:37 QUOTE

Nice job.

Looks like a good candidate for addition to a future release.
Back to top
Profile PM 
newOldUser Offline





Group: Members
Posts: 241
Joined: Oct. 2004
Posted: July 14 2005,23:39 QUOTE

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* "
Back to top
Profile PM 
Joat_Mone Offline





Group: Members
Posts: 36
Joined: Oct. 2004
Posted: Aug. 02 2005,02:15 QUOTE

What about those who arent using eth0?  My network device is ath0 (wireless PCMCIA card).  I see where I can change the script, but if you want it universal you might want to have a drop down list where you can select the appropriate device.  Just a suggestion.
Back to top
Profile PM 
4 replies since July 01 2005,21:29 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: Show IP Address

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code