Welcome, Guest

Please login or register

FORUMS SUBMENU

Register Forum Rules Members List Social Groups Search Today's Posts Mark Forums Read
BioRUST Forums > Graphics Software & Support > HTML / PHP / ASP / JS > PERL - extracting output of ifconfig to get local system IP address...
Sponsored Links

Thread: PERL - extracting output of ifconfig to get local system IP address...

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-28-2006   #1
Registered User
 
thecubed's Avatar
 

Join Date: Jun 2004
Location: Infront of my screen (most of the time)
Posts: 89

Send a message via AIM to thecubed Send a message via Yahoo to thecubed Send a message via Skype™ to thecubed
PERL - extracting output of ifconfig to get local system IP address...

Hello again!

I was wondering if anyone knew how to extract the output of /sbin/ifconfig on a Linux system, and feed it into a Perl variable.
The reason for this is that I am building a computer that will run without a monitor, keyboard, or mouse, and will act as a network video streamer... it has an internal charactor LCD that will be used to display ip address and other statistics of the machine (see http://thecubed.com/tc-blog/?p=6 ).
I am using a program called LCDd (part of LCDproc) to control the LCD and yaLCD (a perl script) to display the information. yaLCD doesn't output the local system's ip address to the LCD screen, so I wanted to modify it.

I've already scoured the internet for answers, and I've only come up with a few things...
I've found this snippet of code, but it only prints "1", and nothing else.
Code:
 my $ip = ((`/sbin/ifconfig eth0`)[1] =~ /inet addr:(\S+)/);
 print $ip;
I know a bit of Perl (it's just like PHP, only more complicated ), but not enough to tell me why this won't work...

Any help is appreciated,
Thanks!
__________________

www.thecubed.com <--- TheCubed Homepage!
thecubed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Old 06-29-2006   #2
Registered User
 
thecubed's Avatar
 

Join Date: Jun 2004
Location: Infront of my screen (most of the time)
Posts: 89

Send a message via AIM to thecubed Send a message via Yahoo to thecubed Send a message via Skype™ to thecubed
Nevermind, I (think) I may have figured it out:
on my windows machine the code would be as follows,
Code:
 my $ip = ((`ipconfig`) =~ /IP Address. . . . . . . . . . . . : (\S+)/);
 $ip = $1; 
 print $ip;
I forgot that regular expressions dumped the parsed string into a variable in order of occurrence- $1,$2,etc... - by asking Perl to print $ip in my previous post, I was only getting the execution status of the regular expression.
(Funny how I answered my own question )

Just thought if anyone else was having the same problem, that might help
__________________

www.thecubed.com <--- TheCubed Homepage!
thecubed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Old 08-14-2006   #3
Registered User
 
Cr0w's Avatar
 

Join Date: Mar 2006
Location: Comodoro Rivadavia, Chubut, ARgentina.
Posts: 22

Send a message via MSN to Cr0w Send a message via Yahoo to Cr0w
hello, u can try to save in the var $ip this:
ifconfig eth0 | grep inet | awk '{print $2}'
u will get addr:0.0.0.0
then..with perl..remove the substring addr: and u get the ip
another way is..if u have internet acces..(i dont know
if that server will be local or public) u can do
/usr/bin/curl -s http://ip.dnsexit.com/ | sed -e 's/ //'
or
/usr/bin/wget -o /dev/null -O - http://ip.dnsexit.com/
i hope this work for u
good bye.

pd: sorry my english.
Cr0w is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Old 08-14-2006   #4
Registered User
 
Cr0w's Avatar
 

Join Date: Mar 2006
Location: Comodoro Rivadavia, Chubut, ARgentina.
Posts: 22

Send a message via MSN to Cr0w Send a message via Yahoo to Cr0w
i have another option..your own script to get the ip:

PHP Code:
<?
function getIP() {
    if (isset(
$_SERVER)) {
        if (isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])) $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
        elseif (isset(
$_SERVER['HTTP_CLIENT_IP'])) $ip $_SERVER['HTTP_CLIENT_IP'];
        else 
$ip $_SERVER['REMOTE_ADDR'];
    }
    else {
        if (
getenv('HTTP_X_FORWARDED_FOR')) $ip getenv('HTTP_X_FORWARDED_FOR');
        elseif (
getenv('HTTP_CLIENT_IP')) $ip getenv('HTTP_CLIENT_IP');
        else 
$ip getenv('REMOTE_ADDR');
    }
    return 
$ip;
}

echo 
getIP();
?>
to use instead ip.dnsexit.com.. www.thecubed.com/ip.php
bye
Cr0w is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A local webhost offer - question. turvas General Discussions 8 03-11-2008 09:27 PM
PHP Output Warnings in Membership System Tash-n HTML / PHP / ASP / JS 8 11-15-2007 12:51 AM
TUT: Extracting images with hair Little_T Tutorial Submission 3 05-09-2006 11:21 PM
Perl? ConceptualMind HTML / PHP / ASP / JS 13 02-19-2004 06:42 PM


All times are GMT +1. The time now is 02:05 PM.

Powered by vBulletin Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2