Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I assume you want a solution that gives you your external IP address from a commandline?
If so, this works - though it may not be the "best":
Code:
wget -q -O - http://www.whatismyipaddress.com | \
grep "Your IP address is" | \
sed 's@.*address is \([^<]\+\).*@\1@'
Each command in the pipeline was put on a separate line to make it easier to see each step--purely aesthetic.
EDIT:
I do something like this for my home server. My router reports its external IP address on its status page. So, I've set up a script to check my router's status page for changes to the external IP address. The script sends an email to an external email account when a change occurs. Because I look at my own router, I don't have a problem with running the script every hour with cron; I'm not causing unnecessary 'net traffic nor am I pestering another person's server with repeated requests.
Last edited by Dark_Helmet; 05-29-2007 at 01:56 AM.
I assume you want a solution that gives you your external IP address from a commandline?
If so, this works - though it may not be the "best":
Code:
wget -q -O - http://www.whatismyipaddress.com | \
grep "Your IP address is" | \
sed 's@.*address is \([^<]\+\).*@\1@'
Each command in the pipeline was put on a separate line to make it easier to see each step--purely aesthetic.
EDIT:
I do something like this for my home server. My router reports its external IP address on its status page. So, I've set up a script to check my router's status page for changes to the external IP address. The script sends an email to an external email account when a change occurs. Because I look at my own router, I don't have a problem with running the script every hour with cron; I'm not causing unnecessary 'net traffic nor am I pestering another person's server with repeated requests.
I noticed they changed the whatismyipaddress.com and use now some Gif of it.
is there a solution via commandline via i dont know maybe traceroute / iptable ... sthg
thank you
It worked for me, you pasted one line in, enter, next, enter, next... then it gives you a white space, just hit enter again, and your IP comes up.
Maybe I don't understand what you're saying. Would whatismyip.com work any better for you?
Thx
No my idea was :
Code:
traceroute google.be
but it didnt work out...
hmm
If I recall well, with IPTABLES, once I was able to see my external ip address ... right or fully wrong ?... that was a long experiment with iptables ... cant recall well
I assume you want a solution that gives you your external IP address from a commandline?
If so, this works - though it may not be the "best":
Code:
wget -q -O - http://www.whatismyipaddress.com | \
grep "Your IP address is" | \
sed 's@.*address is \([^<]\+\).*@\1@'
Each command in the pipeline was put on a separate line to make it easier to see each step--purely aesthetic.
EDIT:
I do something like this for my home server. My router reports its external IP address on its status page. So, I've set up a script to check my router's status page for changes to the external IP address. The script sends an email to an external email account when a change occurs. Because I look at my own router, I don't have a problem with running the script every hour with cron; I'm not causing unnecessary 'net traffic nor am I pestering another person's server with repeated requests.
Concerning this:
I am interested:
EDIT:
I do something like this for my home server. My router reports its external IP address on its status page. So, I've set up a script to check my router's status page for changes to the external IP address. The script sends an email to an external email account when a change occurs. Because I look at my own router, I don't have a problem with running the script every hour with cron; I'm not causing unnecessary 'net traffic nor am I pestering another person's server with repeated requests.
Dont you have a login and password to access your router ??
that a big not easy to access this router status information no ??
thank you
that s the greatest ideao to check the status router page ... ... pswd problem ... hmm
#!/bin/bash
# ======================================================================
# /home/user/cvsroot/src/utilities/external_ip/external_ip.bash,v
# ======================================================================
# Description:
# This script sends an email to an external email service to notify
# users when this machine's external IP address changes. The IP address
# is read from the local router connected to the ISP. The router's
# administrator status page lists the external IP address.
#
# The general flow of the script is:
# 1. Retrieve the last known IP address (stored in a file)
# 2. Use wget to read the router's status page
# 3. Grep the router's status page for the IP address
# 4. Send an email to an external email address if the last IP
# address differs from the current one.
#
# The script should run regularly--through cron or an equivalent.
# ======================================================================
# ======================================================================
# Variables to customize the script's operation
#
# Perhaps some of these should be supported by command line arguments
# ======================================================================
WGET=/usr/bin/wget
EGREP=/bin/egrep
ECHO=/bin/echo
RM=/bin/rm
MKDIR=/bin/mkdir
MUTT=/pkgs/inst/mutt/bin/mutt
MAC2UNIX=/pkgs/inst/mac2unix/bin/mac2unix
DATE=/bin/date
CAT=/bin/cat
DIRNAME=/usr/bin/dirname
# Customize these variables
ROUTER_IP_ADDRESS=???.???.???.???
PAGE_NAME=???
TEMP_DIR=???
USERNAME=???
PASSWORD=???
DATA_FILE=???
EMAIL_ADDRESS=???
# ======================================================================
# Start of the script.
# 1. Retrieve the last known IP address (stored in a file)
#
# If the data file does not exist, use a default value to guarantee a
# mismatch with the new IP address
# ======================================================================
if [ -e ${DATA_FILE} ] ; then
LAST_IP_ADDRESS=$( ${CAT} ${DATA_FILE} )
else
LAST_IP_ADDRESS=xxx.xxx.xxx.xxx
fi
# ======================================================================
# Create a temporary directory to put files as they're created.
#
# Use a self-contained directory for easy cleanup at the end of the
# script.
#
# Assume this script is the only thing using the temp directory. Delete
# any prior copy of the temp directory and make a new one.
# -- The directory might exist if a previous run were interrupted or
# killed during execution.
# ======================================================================
if [ -d "${TEMP_DIR}" ] ; then
${RM} -rf "${TEMP_DIR}"
fi
${MKDIR} -p "${TEMP_DIR}"
# ======================================================================
# Next major section of the script
# 2. Use wget to read the router's status page
#
# This is unique for my setup. To get the router's status page, my
# router requires an administrator login. The router denies access on
# the first attempt--don't know why. An immediate, subsequent attempt
# with the same credentials succeeds.
#
# To accomodate the router, the script uses a loop. It repeatedly
# requests the same page with the same credentials until the script
# reaches a maximum number of retries, or succeeds.
#
# Also, the router's statuts page is returned with Mac line endings.
# The line endings must be converted to Unix line endings or grep will
# not give good results.
# ======================================================================
wget_counter=0
wget_success=0
while [ \( ${wget_counter} -lt 10 \) -a \( ${wget_success} -ne 1 \) ] ; do
${WGET} --quiet \
--http-user=${USERNAME} \
--http-passwd=${PASSWORD} \
--directory-prefix="${TEMP_DIR}" \
"http://${ROUTER_IP_ADDRESS}/${PAGE_NAME}"
wget_result=$?
if [ ${wget_result} -ne 0 ] ; then
let wget_counter=wget_counter+1
else
wget_success=1
fi
done
# If wget_counter is equal to the maximum number of retries, then
# quit; we don't have a page to grep against.
if [ ${wget_counter} -eq 10 ] ; then
exit 1
fi
${MAC2UNIX} "${TEMP_DIR}/${PAGE_NAME}"
# ======================================================================
# Next major section of the script
# 3. Grep the router's status page for the IP address
#
# At this point, the status page is available. Extract the new IP
# address from the page.
#
# My router returns a page with the external IP address is on a line
# of its own. In addition, the line with the external IP address is the
# only line that starts with a numeric digit.
# ======================================================================
new_ip_address=$( ${EGREP} "^[0-9]" "${TEMP_DIR}/${PAGE_NAME}" )
# ======================================================================
# Next major section of the script
# 4. Send an email to an external email address if the last IP
# address differs from the current one.
#
# At this point, the current IP address is available. Compare it
# against the old IP address. If the IP addresses are different, send a
# notification email with the current IP address. If the IP addresses
# are the same, do nothing.
#
# Do not update the IP address stored in the data file if the command
# to email user(s) fails. This guarantees the stored IP address will
# differ from the current IP address the next time the script is run--
# causing another email attempt to notify the user(s).
# ======================================================================
if [ ${new_ip_address} != ${LAST_IP_ADDRESS} ] ; then
${ECHO} "New IP address detected at $( ${DATE} )" | \
${MUTT} -s "New Router IP address: ${new_ip_address}" ${EMAIL_ADDRESS}
mail_success=$?
if [ ${mail_success} -eq 0 ] ; then
if [ -e ${DATA_FILE} ] ; then
${ECHO} "${new_ip_address}" > ${DATA_FILE}
else
${ECHO} "Error: No data file to store new IP address in!" >&2
fi
fi
fi
# Cleanup the temporary workspace
${RM} -rf "${TEMP_DIR}"
exit 0
If you want to use this script, make sure you read the comments to fully understand what the script is doing, and know how to modify it for your needs.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.