Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
#!/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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.