Sponsored Content
Top Forums Shell Programming and Scripting Script getting IP's and MAC addresses Post 303006604 by hermouche on Saturday 4th of November 2017 12:21:11 PM
Old 11-04-2017
Quote:
Originally Posted by RudiC
OK, let's combine the two. Try

Code:
sed -n '/hardware ethernet/ {s///; h; d;}; /fixed-address / {s///; G; s/[;\n]//g; s/ / -m --mac-source /; s/^/iptables -I FORWARD -s /; s/$/ -j ACCEPT/; p;}' dhcp.conf

Actually, you don't need a script to execute this. In a recent bash,

you can deploy "process substitution" for the sourceing:
Code:
. <(sed -n '/hardware ethernet/ {s///; h; d;}; /fixed-address / {s///; G; s/[;\n]//g; s/ / -m --mac-source /; s/^/iptables -I FORWARD -s /; s/$/ -j ACCEPT/; p;}'  dhcp.conf)

And, if you need this frequently, add an alias definition to your .profile:
Code:
alias FWD=". <(sed -n '/hardware ethernet/ {s///; h; d;}; /fixed-address /  {s///; G; s/[;\n]//g; s/ / -m --mac-source /; s/^/iptables -I  FORWARD -s /; s/$/ -j ACCEPT/; p;}'  dhcp.conf)"

I am sorry, RudiC,

The following is what i typed (code):
Code:
sed -n '/hardware ethernet/ {s///; h; d;}; /fixed-address / {s///; G; s/[;\n]//g; s/ / -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source /; s/^/iptables -I FORWARD -s /; s/$/ -j ACCEPT/; p;}' dhcpd.conf

This is my result so far:
Code:
iptables -I FORWARD -s  -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source                192.168.0.208                 30:10:B3:42:40:46 -j ACCEPT

This is how it should be:
Code:
iptables -I FORWARD -s 192.168.0.208 -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source 30:10:B3:42:40:46 -j ACCEPT

And that's part of my dhcpd.conf file:

Code:
#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

## by red: ICI on desire reserver des adresses IP fixes a des machines ##
group {
        use-host-decl-names true;


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


        host yacine {
                hardware ethernet E8:50:8B:E1:E9:35;
                fixed-address 192.168.0.253;
                }

        host hanane {
                hardware ethernet 3C:FA:43:B1:13:3A;
                fixed-address 192.168.0.252;
                }

Thanks.


Moderator's Comments:
Mod Comment Please use CODE (not QUOTE) tags as required by forum rules!

Last edited by RudiC; 11-05-2017 at 06:07 AM.. Reason: Changed QUOTE to CODE tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Mac addresses of NICs (why are they the same)

I am training to be support on our solaris based network and was wondering why solaris seems to assign the same mac address to all NICs placed in the machine regardless of how many NICs are in there, when i do a ifconfig -a all nics have same MAC. Presumably this is a feature and there is... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

2. Shell Programming and Scripting

Script to get IP addresses of LAN computers

I need a shell script for OS X, one that can find IP addresses of machines connected to my LAN, get the names of the computer associated with those addresses, then display them like so in a list: "Bob's L33T Boxx: #.#.#.#" Something like the network scanner in Apple Remote Desktop is what I'm... (1 Reply)
Discussion started by: sladuuch
1 Replies

3. UNIX for Dummies Questions & Answers

Help extracting MAC addresses from List

Hello all. I have a large number of text files outputted from various Netstumbler Wireless Scans; from which I need to extract the MAC addresses of the various Access Points. The Text files look like this: # $Creator: Network Stumbler Version 0.4.0 # $Format: wi-scan summary with... (9 Replies)
Discussion started by: dhs23
9 Replies

4. Shell Programming and Scripting

Need help with IP and MAC addresses

Hi, i am working on a project where i have to write a script to find out MAC addresses of the systems with given IP address. Can anybody tell me which command i can use to find MAC address if you know IP address of the machine. Thanks (5 Replies)
Discussion started by: manmeet
5 Replies

5. Shell Programming and Scripting

Help with bash script to block IP addresses

I am using a bash script for CentOS 5.5, I found one and modified it, however I want to block the incoming IP addresses and ALLOW the IP addresses that are blocked to send out email. I will use an internal network range for an example, 10.10.10.0/24 (if a lot of spam is incoming) from this range... (0 Replies)
Discussion started by: grifs71
0 Replies

6. Shell Programming and Scripting

script to get all ip addresses of servers into a file

Hi all i need to create a script that pings every server in my range (0-254) adn then returns the values to a file? can anyone please help. i am working in the tcsh ( and yes i know how to ping ) but i dont know how to ping them all in one script without copying and pasting a 254 times? ... (1 Reply)
Discussion started by: brian112
1 Replies

7. UNIX for Dummies Questions & Answers

Difference between Mac and IP addresses

If a web search is done on this topic there are many links but no information included in the documents. So my questions are; Why does a NIC card have it's own permanent ID. Why can't it share the host name? An ID is an ID. Why does a computer need two ways to ID it. If the network... (3 Replies)
Discussion started by: theKbStockpiler
3 Replies

8. Windows & DOS: Issues & Discussions

Script to ftp in to multiple ip addresses

Hello Is there an easy way to login to various ip's..one after the other. I need to login to about 30 aix boxes and put a file in each one... Cheers (1 Reply)
Discussion started by: Grueben
1 Replies

9. UNIX for Dummies Questions & Answers

Script to ftp in to multiple ip addresses

Hello Is there an easy way to login to various ip's..one after the other. I need to login to about 30 aix boxes and put a file in each one... Cheers (1 Reply)
Discussion started by: Grueben
1 Replies

10. Shell Programming and Scripting

Don't see my mac addresses of my devices

I have a problem with a script , i want to see my devices there are up in my network. I want as output the ip addresses of the devices and also the mac address but I only had the ip addresses #!/bin/bash while ] do -mac) Extension=5 shift mac=$1 shift ;; esac... (1 Reply)
Discussion started by: Roggy
1 Replies
All times are GMT -4. The time now is 10:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy