Sponsored Content
Top Forums Shell Programming and Scripting Listing IPs from the dhcpd.conf Post 303007409 by RudiC on Thursday 16th of November 2017 07:27:17 AM
Old 11-16-2017
Quote:
Originally Posted by hermouche
. . . so ?!
I was thinking about applying some exercise and creativity? How about

Code:
awk -F"[ ;]*" '
/^subnet/       {SUBNET = $2
                }
/^ *host.* {/   {getline
                 TMP = $4
                 getline
                 FXIP[$3] = TMP
                }
END             {sub (/[^.]*$/, "", SUBNET)
                 for (i=1; i<25; i++)   {TMP = sprintf ("%s%d", SUBNET, i) 
                                         printf "iptables -I FORWARD -s %s", TMP
                                          if (TMP in FXIP)       print " -p tcp -m multiport --dports  110,143,25,465,585,993,995,80,443 -m mac --mac-source " FXIP[TMP] " -j  ACCEPT"
                                           else                 print " -j DROP"
                                        }
                 for ( f in FXIP) print FXIP[f], f , " > ./etc_ethers"
                }
' dhcpd.conf
iptables -I FORWARD -s 192.168.0.1 -j DROP
iptables -I FORWARD -s 192.168.0.2 -j DROP
iptables -I FORWARD -s 192.168.0.3 -j DROP
iptables -I FORWARD -s 192.168.0.4 -j DROP
iptables -I FORWARD -s 192.168.0.5 -j DROP
iptables -I FORWARD -s 192.168.0.6 -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source 00:71:CC:6E:A3:33 -j ACCEPT
iptables -I FORWARD -s 192.168.0.7 -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source C0:38:96:72:8B:5B -j ACCEPT
iptables -I FORWARD -s 192.168.0.8 -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source 08:ED:B9:08:94:09 -j ACCEPT
iptables -I FORWARD -s 192.168.0.9 -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source D0:53:49:CB:FE:0F -j ACCEPT
iptables -I FORWARD -s 192.168.0.10 -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source C4:8E:8F:8F:45:A7 -j ACCEPT
iptables -I FORWARD -s 192.168.0.11 -j DROP
iptables -I FORWARD -s 192.168.0.12 -j DROP
iptables -I FORWARD -s 192.168.0.13 -j DROP
iptables -I FORWARD -s 192.168.0.14 -j DROP
iptables -I FORWARD -s 192.168.0.15 -j DROP
iptables -I FORWARD -s 192.168.0.16 -j DROP
iptables -I FORWARD -s 192.168.0.17 -j DROP
iptables -I FORWARD -s 192.168.0.18 -j DROP
iptables -I FORWARD -s 192.168.0.19 -j DROP
iptables -I FORWARD -s 192.168.0.20 -j DROP
iptables -I FORWARD -s 192.168.0.21 -j DROP
iptables -I FORWARD -s 192.168.0.22 -j DROP
iptables -I FORWARD -s 192.168.0.23 -j DROP
iptables -I FORWARD -s 192.168.0.24 -j DROP
D0:53:49:CB:FE:0F 192.168.0.9  > ./etc_ethers
08:ED:B9:08:94:09 192.168.0.8  > ./etc_ethers
C0:38:96:72:8B:5B 192.168.0.7  > ./etc_ethers
00:71:CC:6E:A3:33 192.168.0.6  > ./etc_ethers
C4:8E:8F:8F:45:A7 192.168.0.10  > ./etc_ethers

Be aware that
- this prints out a subset (1 - 25) of the IP range in question, intentionally
- fakes the redirection into an "ethers" file
- could be enhanced to calculate the IP range from subnet and netmask instead of using fixed IPs
 

10 More Discussions You Might Find Interesting

1. Linux

dhcpd.conf

I have intall a REdhat 9.0 as a server and Ive configure to act as a DHCP however Im having technical problems b/c the file /etc/dhcpd.conf does not exists. I went to the text edit and I created : subnet 192.192.168.100.0 netmask 255.255.255.0 { range 192.168.100.10 192.168.100.150;... (1 Reply)
Discussion started by: keliy1
1 Replies

2. Shell Programming and Scripting

Shell/Perl Script to edit dhcpd.conf

Hi, I need to get a script together to edit the dhcp service configuration file dhcpd.conf. Mac addresses are defined in classes ex. class "HOST1" { match if substring (hardware, 1,18)=00:11:11:FF:FF:FF;} class "HOST2" ... class "HOST3" ... ... followed by allow or deny statements:... (4 Replies)
Discussion started by: sahilb
4 Replies

3. Linux

dhcpd.conf - static route

Hi, I've setup DHCP Server on RH linux AS3 and everything works fine except static routes. They are not getting effected on client systems. My dhcpd.conf: +++++++++++ ddns-update-style interim; ddns-updates off; option domain-name-servers 192.168.116.122; option domain-name... (3 Replies)
Discussion started by: prvnrk
3 Replies

4. UNIX for Advanced & Expert Users

Configuring snmpd.conf and snmptrapd.conf

HI, I want a help for Configuring snmpd.conf and snmptrapd.conf (i.e Configuring SNMP) for receiving TRAPS in my networks. I am using RHEL4.0 OS. Please tell me How I can configure above two files in a proper way and at an advanced level. Especially I am getting... (2 Replies)
Discussion started by: jagdish.machhi@
2 Replies

5. Solaris

basic question on sd.conf and lpc.conf file

Hello Guys, Do we need to configure this file only if we add SAN disk or even if we add local disk, do we need to modify? (4 Replies)
Discussion started by: mokkan
4 Replies

6. Shell Programming and Scripting

Help with Perl to change dhcpd.conf file

Hi all, I am too new for this stuff and i am lost in perl tutorials. I need help to change dhcp entries in .conf file with a perl script. The file entries are like below : host bertha-clp-0 { hardware ethernet AA:0A:A0:00:6c:40; fixed-address 10.10.10.72; option... (6 Replies)
Discussion started by: ekckabatop
6 Replies

7. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

8. Shell Programming and Scripting

Script to update rsyslog.conf and auditd.conf

Hello all, Newbie here. I'm currently tasked with updating rsyslog.conf and auditd.conf on a large set of servers. I know the exact logging configurations that I want to enable. I have updated both files on on a server and hope to use the updated files as a template for the rest of the... (3 Replies)
Discussion started by: Mide
3 Replies

9. Solaris

Configure resolv.conf and nsswitch.conf

Hi, I've installed Solaris 11.3(live media) and configured DNS. Everytime I reboot the server, resolv.conf got deleted and it created a new nsswitch.conf. I used below to configure both settings: # svccfg -s dns/client svc:/network/dns/client> setprop config/nameserver = (xx.xx.xx.aa... (1 Reply)
Discussion started by: flexihopper18
1 Replies

10. UNIX for Beginners Questions & Answers

Changes in dhcpd.conf do not make a difference in DHCP service behaviour

Hi Experts, Our DHCP server currently answers the DHCP Discover requests from ServerX. In our dhcpd.conf file there are parameters defined for ServerX. Now we introduced some additional Servers into the network and want them to get service from the same DHCP server. Similar configuration... (13 Replies)
Discussion started by: ekorgur
13 Replies
GETLINE(3)						     Linux Programmer's Manual							GETLINE(3)

NAME
getline, getdelim - delimited string input SYNOPSIS
#include <stdio.h> ssize_t getline(char **lineptr, size_t *n, FILE *stream); ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): Before glibc 2.10: getline(), getdelim(): _GNU_SOURCE Since glibc 2.10: getline(), getdelim(): _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700 DESCRIPTION
getline() reads an entire line from stream, storing the address of the buffer containing the text into *lineptr. The buffer is null-termi- nated and includes the newline character, if one was found. If *lineptr is NULL, then getline() will allocate a buffer for storing the line, which should be freed by the user program. (In this case, the value in *n is ignored.) Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc(3)-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary. In either case, on a successful call, *lineptr and *n will be updated to reflect the buffer address and allocated size respectively. getdelim() works like getline(), except a line delimiter other than newline can be specified as the delimiter argument. As with getline(), a delimiter character is not added if one was not present in the input before end of file was reached. RETURN VALUE
On success, getline() and getdelim() return the number of characters read, including the delimiter character, but not including the termi- nating null byte. This value can be used to handle embedded null bytes in the line read. Both functions return -1 on failure to read a line (including end-of-file condition). ERRORS
EINVAL Bad arguments (n or lineptr is NULL, or stream is not valid). VERSIONS
These functions are available since libc 4.6.27. CONFORMING TO
Both getline() and getdelim() were originally GNU extensions. They were standardized in POSIX.1-2008. EXAMPLE
#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> int main(void) { FILE *fp; char *line = NULL; size_t len = 0; ssize_t read; fp = fopen("/etc/motd", "r"); if (fp == NULL) exit(EXIT_FAILURE); while ((read = getline(&line, &len, fp)) != -1) { printf("Retrieved line of length %zu : ", read); printf("%s", line); } free(line); exit(EXIT_SUCCESS); } SEE ALSO
read(2), fgets(3), fopen(3), fread(3), gets(3), scanf(3), feature_test_macros(7) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2010-06-12 GETLINE(3)
All times are GMT -4. The time now is 07:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy