473,385 Members | 1,569 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,385 software developers and data experts.

Help me Extract a MAC Address

Im trying to extract the Mac address from ifconfig eth0

$HWAddr = `ifconfig eth0`;


$HWAddr= m/([0-9a-fA-F]{0,2})[:]?([0-9a-fA-F]{0,2})[:]?([0-9a-fA-F]{0,2})[:]?([0-9a-fA-F]{0,2})[:]?([0-9a-fA-F]{0,2})[:]?([0-9a-fA-F]{0,2})/g;
But being a perl newbie im really struggling, any help much appreciated :)

LH
Mar 20 '06 #1
2 6250
hacker
2
[quote=leehaggan]Im trying to extract the Mac address from ifconfig eth0

There are several modules that do this in CPAN. Look in Net::Packet::Utils for starters.

Peace,
Hacker
Aug 10 '06 #2
Here is a quick script I chruned out. It could be neatened up a bit, naturally, but should get you where you want to go.


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. $ifconfigin= `/sbin/ifconfig eth0`;
  3. @ifeth = split(/\n/, $ifconfigin);
  4. ($junk,$macaddr) = split(/ HWaddr /, $ifeth[0]);
  5. print "$macaddr\n";

Dave
http://www.flanigan.net
Aug 16 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: MJ | last post by:
I'm having problems coming up with a regular expression that works for what I want. I need to extract a few numbers from from html. Here's a snippet: <tr><td align="right">Consolidated Metro...
0
by: Learning.PHP | last post by:
I am trying to make a simple web tool that will log into a POP3 mailbox and delete the messages all at once. I have came up with this and if the Login information is correct it does delete the...
4
by: David Chang | last post by:
I am trying to do some analysis on customer's locality, so I'd like to extract numeric part from address. Here is how the table looks like Table Member first_name last_name address1 ...
2
by: linsnail2 | last post by:
Hi, First of all, this is a naive question and I am not sure if Ms Access help me automatically generate a report. An experiment data are recorded in A.rec. This text file looks like the...
6
by: james | last post by:
I will try to make this short and to the point. I am reading values from a file using a Binary Reader. At a particular address I can get a value of , Hex 10 or Hex 01 . (varies can be 30, 20, 02,03...
1
by: Petra Meier | last post by:
Hi, I hope this is a proper place to post :) This is my XML file: <?xml version="1.0" encoding="utf-8"?> <foo> <address>a lot of tags and text</address> <hubid>a lot of tags and text</hubid>...
2
by: akhilak | last post by:
Hi, I am using XPath to retrieve the node data from an XML file. I used the following code to extract the attribute data from the file. I manually entered the attribute name in the code and I am...
4
by: Farooqui | last post by:
Hi, I need help in writing a VB6 program to read 1000 word documents and extract my required information into a .dbf file. All word documents are having different information in a tabular form...
2
by: hutch75 | last post by:
Hi All - chasing down a means to initiate a traceroute, record results, and extract IP addresses in an (array?) Here's what I'm thinking about so far, wonder if anyone's been down this road before...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.