CarlPender
Technical User
Hi, I have a Suse7.3 Linux PC acting as a gateway with an APache server running. I have a web site set up and what I want to do is allow only certain MAC addresses onto the network as I choose. I have a script that adds certain MAC addresses onto the network which works perfectly if I type the MAC address in manually but I need to automate it. I'll nearly there I think but I need a little help.
Here goes.... I have a acript that matches an IP
address with it's respective MAC address via the
'arp' command. The script is as follows:
#!/bin/bash
sudo arp > /usr/local/apache/logs/users.txt
sudo awk '{if ($1 =="157.190.66.1" print $3}'
/usr/local/apache/logs/users.txt |
/usr/local/apache/cgi-bin/add
Here is a typical output from the arp command:
Address HWtype HWaddress Flags Mask Iface
157.190.66.13 ether 00:10:5A:B0:30:ED C eth0
157.190.66.218 ether 00:10:5A:5B:6A:11 C eth0
157.190.66.1 ether 00:60:5C:2F:5E:00 C eth0
As you can see I send this to a text file from which I
capture the MAC address for the respective IP address
("157.190.66.1" and then send this MAC address to
another script, called "add", which allows this MAC
address onto the network. This works perfectly when I
do it from a shell with the ip address typed in
maually.
My problem is that instead of actually typing in the
IP address (e.g "157.190.66.1", I want to be able to
pipe the remote IP address of the user that is
accessing my web page at the time to this script as an
input.
In order to do this, I tried:
#!/bin/bash
read ip_address
sudo arp > /usr/local/apache/logs/users.txt
sudo awk '{if ($1 ==$ip_address) print $3}'
/usr/local/apache/logs/users.txt |
/usr/local/apache/cgi-bin/add
But I'm afraid this doesn't work. I'm wondering where
I'm going wrong. I also tried putting quotations
around the variable $ip_address but that doesn't work
either. On my CGI script I have the line 'echo
"$RENOTE_ADDR" | /usr/local/apache/cgi/bin/change' to
pipe the ip address of the user. I know this is
working because if I include the line 'echo
"$ip_address"' in my script then the ip address is
echoed to the screen
Basically what I want to know is how do you pipe something to a script(e.g. an IP address) and then use this variable in the awk script
I hope that I have made myself clear.
Thanks
Carl
Here goes.... I have a acript that matches an IP
address with it's respective MAC address via the
'arp' command. The script is as follows:
#!/bin/bash
sudo arp > /usr/local/apache/logs/users.txt
sudo awk '{if ($1 =="157.190.66.1" print $3}'
/usr/local/apache/logs/users.txt |
/usr/local/apache/cgi-bin/add
Here is a typical output from the arp command:
Address HWtype HWaddress Flags Mask Iface
157.190.66.13 ether 00:10:5A:B0:30:ED C eth0
157.190.66.218 ether 00:10:5A:5B:6A:11 C eth0
157.190.66.1 ether 00:60:5C:2F:5E:00 C eth0
As you can see I send this to a text file from which I
capture the MAC address for the respective IP address
("157.190.66.1" and then send this MAC address to
another script, called "add", which allows this MAC
address onto the network. This works perfectly when I
do it from a shell with the ip address typed in
maually.
My problem is that instead of actually typing in the
IP address (e.g "157.190.66.1", I want to be able to
pipe the remote IP address of the user that is
accessing my web page at the time to this script as an
input.
In order to do this, I tried:
#!/bin/bash
read ip_address
sudo arp > /usr/local/apache/logs/users.txt
sudo awk '{if ($1 ==$ip_address) print $3}'
/usr/local/apache/logs/users.txt |
/usr/local/apache/cgi-bin/add
But I'm afraid this doesn't work. I'm wondering where
I'm going wrong. I also tried putting quotations
around the variable $ip_address but that doesn't work
either. On my CGI script I have the line 'echo
"$RENOTE_ADDR" | /usr/local/apache/cgi/bin/change' to
pipe the ip address of the user. I know this is
working because if I include the line 'echo
"$ip_address"' in my script then the ip address is
echoed to the screen
Basically what I want to know is how do you pipe something to a script(e.g. an IP address) and then use this variable in the awk script
I hope that I have made myself clear.
Thanks
Carl