LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   Laptop Firewall Considerations - MAC Addresses (https://www.linuxquestions.org/questions/linux-security-4/laptop-firewall-considerations-mac-addresses-594068/)

win32sux 10-28-2007 10:32 AM

If the OR operator (||) works the same in a conditional statement as it does on the command-line, then the part after the || would only be looked at if the part before it fails (or in this case, evaluates to false). In other words, the statement would evaluate to true if either part succeeds. Are you trying to get it to skip the WAN IP check if you have a dynamic IP? Perhaps we would be better-off simply forgetting about the WAN IP check and instead have your home router's DHCP server assign a non-typical "static" IP to your laptop all the time (something like 192.168.192.235 or whatever). Then we just check to see if we have that IP. Considering neither approach is secure, we aren't giving anything up. We actually gain not having to depend on the whatismyip.org server. It's just a thought.

Meson 10-28-2007 10:52 AM

I agree. I like when things work in the most general case. And you can't assume all networks are connected to the internet.

win32sux 10-28-2007 11:04 AM

Well, it could be done like this then:
Code:

#!/bin/sh

# This script will execute a certain script if it detects that your
# router's MAC address, your host IP address, and your hostname are what
# they would be when at home. It'll also execute a certain script if
# it finds that they aren't.

# Set the specs for your home network here:
ROUTER_MAC="xx:xx:xx:xx:xx:xx"
HOST_IP="xxx.xxx.xxx.xxx"
HOST_IFACE="eth0"
HOSTNAME="xxxxxxxxxxxxxxx"

# Set the scripts to be executed after determination is made:
AT_HOME_SCRIPT="/home/meson/firewall-samba.txt"
NOT_AT_HOME_SCRIPT="/home/meson/firewall-stealth.txt"

# Now we get the specs of the network you are currently in:
CURRENT_ROUTER_MAC=$(arping -c1 $(route -n | grep ^0.0.0.0 | awk '{print $2}') \
                  2> /dev/null | grep "Unicast reply from" | awk '{print $5}' \
                  | cut -c 2-18)
CURRENT_HOST_IP=$(ifconfig | grep -A 1 $HOST_IFACE | tail -n 1 | \
                awk '{print $2}' | awk -F: '{print $2}')
CURRENT_HOSTNAME=$(hostname)

# Now we check if they all match, and execute the appropriate script depending
# on whether or not they did:
if [ $CURRENT_ROUTER_MAC = $ROUTER_MAC ] && [ $CURRENT_HOST_IP = $HOST_IP ] \
    && [ $CURRENT_HOSTNAME = $HOSTNAME ]; then
  sh $AT_HOME_SCRIPT
else
  sh $NOT_AT_HOME_SCRIPT
fi



All times are GMT -5. The time now is 03:50 AM.