Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 575083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:53:59+00:00 2026-05-13T13:53:59+00:00

I Try to parse my dhcpd.lease File with Basel. A typical entry looks like

  • 0

I Try to parse my dhcpd.lease File with Basel. A typical entry looks like this:

lease 192.168.20.4 {
    starts 6 2009/06/27 00:40:00;
    ends 6 2009/06/27 12:40:00;
    hardware ethernet 00:00:00:00:00:00;
    uid 00:00:00:00:00:00;
    client-hostname "examle-workstation1";
}

All information i get is the MAC and what i want ist the IP and the client-hostname. But maybe, there is no client-hostname. The entry looks like this:

lease 192.168.20.5 {
    starts 6 2009/06/27 00:40:00;
    ends 6 2009/06/27 12:40:00;
    hardware ethernet 00:00:00:00:00:00;
}

My first idea was to grep the lease attribute, the hardware ethernet attribute and the uid attribute and putt it all on one line. And then parse it.

But my problem is, i have a big file with many entries allocated in many files. The tree looks like this:

dhcpd-leases
-- 192.168.20.0
-- 192.168.30.0
-- 192.168.40.0
[...]

And all what i get ist the MACs parsed from another files in to a list. So i start with this list and want to grep the Attributes ip, mac with my MAC:

for ENTRY in $MACLIST
do
    VAR$(cat "dhcpd-leases/10.148.$NETWORK.2/dhcpd.leases" | grep -E "$MAC|lease|client-hostname")
    echo $VAR
done

But it because of the many entrys in the $VAR and the files im unable to Parse it out right.

Can somenone help?

Best regards
Peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:53:59+00:00Added an answer on May 13, 2026 at 1:53 pm

    assuming your maclist file look like this (just one entry for example)

    $ cat maclist
    00:00:00:00:00:01
    

    and your lease file like this

    $ cat file
    lease 192.168.20.4 {
        starts 6 2009/06/27 00:40:00;
        ends 6 2009/06/27 12:40:00;
        hardware ethernet 00:00:00:00:00:00;
        uid 00:00:00:00:00:00;
        client-hostname "examle-workstation1";
    }
    
    lease 192.168.20.5 {
        starts 6 2009/06/27 00:40:00;
        ends 6 2009/06/27 12:40:00;
        hardware ethernet 00:00:00:00:00:00;
    }
    
    lease 192.168.20.6 {
        starts 6 2009/06/27 00:40:00;
        ends 6 2009/06/27 12:40:00;
        hardware ethernet 00:00:00:00:00:01;
        uid 00:00:00:00:00:01;
        client-hostname "examle-workstation2";
    }
    
    
    lease 192.168.20.7 {
        starts 6 2009/06/27 00:40:00;
        ends 6 2009/06/27 12:40:00;
        hardware ethernet 01:00:00:00:00:00;
    }
    

    you can try this

    awk 'BEGIN{
        while( (getline line < "maclist") > 0){
            mac[line]
        }
        RS="}"
        FS="\n"
    }
    /lease/{
        for(i=1;i<=NF;i++){
            gsub(";","",$i)
            if ($i ~ /lease/) {
                m=split($i, IP," ")
                ip=IP[2]
            }
            if( $i ~ /hardware/ ){
                m=split($i, hw," ")
                ether=hw[3]
            }
            if ( $i ~ /client-hostname/){
                m=split($i,ch, " ")
                hostname=ch[2]
            }
            if ( $i ~ /uid/){
                m=split($i,ui, " ")
                uid=ui[2]
            }
        }
        if ( ether in mac ){
            print "ip: "ip " hostname: "hostname " ether: "ether " uid: "uid
        }
    } ' file
    

    output

    $ ./shell.sh
    hostname: "examle-workstation2" ether: 00:00:00:00:00:01 uid: 00:00:00:00:00:01
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

maybe this is a n00b-question. I try to parse an xml-file like that: <?xml
When I try to parse XML with lxml like this: tree = etree.parse('xml.xml') I
struct is necessary when you try to parse some file format like ELF, etc...
I'm try to parse this xml, but c# keeps throwing an exception saying it
I have a xml file which contains arabic characters.When i try to parse a
I have a JSON which I get from web application. I try this parse
I Try to parse a Json feed with IOS 5. My Json File is
i try to parse an rdf file using android.sax and android.utils.Xml methods. My parser
I try to parse articles from wikipedia. I use the *page-articles.xml file, where they
I try to parse an xml file. The text which is in tags is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.