FedoraForum.org - Fedora Support Forums and Community
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Location
    Algeria
    Posts
    828

    script getting IP's and MAC addresses

    Hy everybody,

    I've a DHCPD running i my server.
    Within the dhcp.conf, we have dedicated fixed IP's for a specific MAC addresses
    i.e:
    Quote:
    host s6 {
    hardware ethernet E8:50:8B:F3:98:F6;
    fixed-address 192.168.0.254;
    }
    We have got about 100 static IP address.
    Is it possible with a bash script, get in a simple text file with two columns one for IP's and the other for their corresponding MAC address?

    i.e:
    Quote:
    192.168.0.254 E8:50:8B:F3:98:F6
    192.168.0.253 xx:xx:xx:xx:xx:xx
    Below is just the head of the dhcpd.conf file:

    #ddns-update-style interim;
    ddns-update-style none;
    ignore client-updates;
    deny client-updates;
    authoritative;

    #### By red for PXE Booting
    allow booting;
    allow bootp;
    ### End by red

    log-facility local6;

    subnet 192.168.0.0 netmask 255.255.255.0 {
    # --- default gateway

    ##### By red for PXE booting
    class "pxeclients" { match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
    next-server 192.168.0.1;
    filename "linux-install/pxelinux.0"; }
    #### End by red

    option routers 192.168.0.1;
    option subnet-mask 255.255.255.0;
    # option nis-domain "domain.org";
    option domain-name "ensm.intranet";
    option domain-name-servers 192.168.0.1;
    option time-offset -18000;
    range dynamic-bootp 192.168.0.5 192.168.0.239;
    default-lease-time 3600;
    max-lease-time 7200;
    # we want the nameserver to appear at a fixed address

    group {
    use-host-decl-names true;

    host s6 {
    hardware ethernet E8:50:8B:F3:98:F6;
    fixed-address 192.168.0.254;

    }
    Thanks a lot for helping me

    Red
    Last edited by hermouche; 4th November 2017 at 11:49 AM.
    IBM ThinkPad z60m

  2. #2
    Join Date
    Oct 2011
    Posts
    1,616

    Re: script getting IP's and MAC addresses

    Following snipped may work but is not error prone to space characters at different places. I should divide each host in one line and then process each host at one time. Replace `/tmp/dhcp.conf` with path to your configuration, optionally add `>` at the end to redirect output to a file.

    Code:
    tr $'\n' @ < /tmp/dhcp.conf | sed 's/@}@/}\n/g' | grep "host.*{.*}" | while read host; do ip=$(echo $host | sed "s/.*fixed-address \(.*\);.*/\1/"); mac=$(echo $host | sed "s/.*hardware ethernet \(.*\);@.*/\1/"); echo "$ip $mac"; done
    Tested on following test file.

    Code:
    $ cat /tmp/dhcp.conf 
    host s6 {
    hardware ethernet E1:50:8B:F3:98:F6;
    fixed-address 192.168.0.1;
    }
    host s6 {
    hardware ethernet E2:50:8B:F3:98:F6;
    fixed-address 192.168.0.2;
    }
    host s6 {
    hardware ethernet E3:50:8B:F3:98:F6;
    fixed-address 192.168.0.3;
    }

  3. #3
    Join Date
    Apr 2006
    Location
    Algeria
    Posts
    828

    Re: script getting IP's and MAC addresses

    Quote Originally Posted by srakitnican
    Following snipped may work but is not error prone to space characters at different places. I should divide each host in one line and then process each host at one time. Replace `/tmp/dhcp.conf` with path to your configuration, optionally add `>` at the end to redirect output to a file.

    Code:
    tr $'\n' @ < /tmp/dhcp.conf | sed 's/@}@/}\n/g' | grep "host.*{.*}" | while read host; do ip=$(echo $host | sed "s/.*fixed-address \(.*\);.*/\1/"); mac=$(echo $host | sed "s/.*hardware ethernet \(.*\);@.*/\1/"); echo "$ip $mac"; done
    Tested on following test file.

    Code:
    $ cat /tmp/dhcp.conf 
    host s6 {
    hardware ethernet E1:50:8B:F3:98:F6;
    fixed-address 192.168.0.1;
    }
    host s6 {
    hardware ethernet E2:50:8B:F3:98:F6;
    fixed-address 192.168.0.2;
    }
    host s6 {
    hardware ethernet E3:50:8B:F3:98:F6;
    fixed-address 192.168.0.3;
    }

    Thanks a lot srakitnican, it works perfectly by doing some modification to my dhcp.conf file. GREAT thank you again

    red
    IBM ThinkPad z60m

Similar Threads

  1. How to add more IP addresses to same NIC?
    By VladImpaled in forum Using Fedora
    Replies: 0
    Last Post: 20th August 2007, 04:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •