473,804 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.1 1.255 Mask:255.255.25 5.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4181661 2 errors:0 dropped:0 overruns:0 frame:0
TX packets:3440770 4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:213769596 4 (2038.6 Mb) TX bytes:339404391 6 (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 13979
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.1 1.255 Mask:255.255.25 5.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4181661 2 errors:0 dropped:0 overruns:0 frame:0
TX packets:3440770 4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:213769596 4 (2038.6 Mb) TX bytes:339404391 6 (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
5387
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
1793
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
22099
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 correctly it seems. Can someone enlightened show a light on this: import socket def getipaddr(hostname='default'): """Given a hostname, perform a standard (forward) lookup and return a list of IP addresses for that host."""
8
4804
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 windows displays). any ideas?? THanks
6
12980
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 addresses are given for my domain name and the ordering is round robin, I cannot tell which one is my real IP address. Is there any way to get my own IP address in C or C++ without using DNS? (such as ifconfig)
13
29124
by: Jay | last post by:
I need to write a program to find mac address of a remote computer, is this possible? How?
29
3899
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
3693
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 suggestion... For Example fconfig eth0 eth0 Link encap:Ethernet HWaddr 00:13:D3:3F:7F:37 inet addr:172.16.170.117 Bcast:172.16.170.255 Mask:255.255.255.0 inet6 addr: fe80::213:d3ff:fe3f:7f37/64 Scope:Link <- here...
13
3480
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 addr:192.168.0.79 Bcast:192.168.0.255 Mask:255.255.255.0
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.