473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

obtain IP address from 'ifconfig' output

Hello, All!

I just started to learn Perl, and don't know exactly what regexp I can use
to get IP address from 'ifconfig' routine. My system is linux, so output is
the following:

eth0 Link encap:Ethernet HWaddr 10:EE:0C:36:8E:C8
inet addr:192.168.11.22 Bcast:192.168.11.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:41816612 errors:0 dropped:0 overruns:0 frame:0
TX packets:34407704 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:2137695964 (2038.6 Mb) TX bytes:3394043916 (3236.8 Mb)
Interrupt:22 Base address:0x8c00

I'd like to save into some variable the value after "inet addr:".

Thank you.

With best regards, Roman Mashak. E-mail: mr*@tusur.ru
Jul 22 '05 #1
1 13956
In article <db***********@relay.tomsk.ru>, Roman Mashak <mr*@tusur.ru>
wrote:
Hello, All!

I just started to learn Perl, and don't know exactly what regexp I can use
to get IP address from 'ifconfig' routine. My system is linux, so output is
the following:

eth0 Link encap:Ethernet HWaddr 10:EE:0C:36:8E:C8
inet addr:192.168.11.22 Bcast:192.168.11.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:41816612 errors:0 dropped:0 overruns:0 frame:0
TX packets:34407704 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:2137695964 (2038.6 Mb) TX bytes:3394043916 (3236.8 Mb)
Interrupt:22 Base address:0x8c00

I'd like to save into some variable the value after "inet addr:".


Something like this (untested):

use strict;
my @lines = `ifconfig`;
my $address;
for( @lines ) {
if /\s*inet addr:([\d.]+)/ ) {
$address = $1;
}
}
if( $address ) {
print "Address found is $address\n";
}

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: olivier Ravard | last post by:
Hi, I want to know the MAC address of my local network card with a python script. I tested the socket module which gives only the IP address. Is someone have an idea ? Thanks. O.R.
6
by: marco | last post by:
I'd search a lot ... but i had not found how can i obtain my ip address (when i'm connected to the www) ?! thanks a lot for any tips marco
7
by: none | last post by:
I want to determine the outside (non local, a.k.a. 127.0.0.x) ip addresses of my host. It seems that the socket module provides me with some nifty tools for that but I cannot get it to work...
8
by: codecraig | last post by:
hi, how can i use python to figure the ip address of the machine which the python script is running on? I dont mean like 127.0.0.1....but i want the external IP address (such as ipconfig on...
6
by: Kazu | last post by:
Hi. I am trying to get my own IP address. I know that there is a way to use gethostname and gethostbyname, but this has a problem. 1. I cannot use this if no DNS is specified. 2. If several IP...
13
by: Jay | last post by:
I need to write a program to find mac address of a remote computer, is this possible? How?
29
by: chellappa | last post by:
hi all I need to write a program to find mac address of a my computer using libaries, is this possible? How? thanks
0
by: prabina | last post by:
hi all, I have faced one problem in ifconfig in linux.I used ifconfig command then after i want delete the IPV6 address permanetly by ifconfig up/down, how is it possible plz give me some...
13
by: Gilles Ganault | last post by:
Hello I need to get the local computer's IP address, ie. what's displayed when running "ifconfig" in Linux: # ifconfig eth0 Link encap:Ethernet HWaddr 00:15:58:A1:D5:6F inet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.