Skip to content

using crontab to polling the ip (using curl to get the public ip, using scp to send it).using node.js to watch the files that hold the ips and show the very freshed ones.

Notifications You must be signed in to change notification settings

RyanChiu/show.me.the.ips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

show.me.the.ips

bash script part

bash script that should be put into one of your machines inside the local subnet which needs to recorgnize the outbound ip.
say, we named the script "sendipout.sh" and make it runnable:
please notice, that, you should replace "yourusername/yourmachinename/yourvmusername/yourvmipaddr" to your own ones. and, of course, set your ssh to yourvm (virtual machine) authorised in order to use scp without password.

curIP=$(curl ifconfig.cc)
loIP=$(cat /home/yourusername/.obip);
echo "current IP: $curIP, local saved IP: $loIP."
if [ "$curIP" = "$loIP" ]; then
        echo "it's a match."
else
        echo $curIP > /home/yourusername/.obip
        scp /home/yourusername/.obip yourvmusername@yourvmipaddr:/home/yourvmusername/.yourmachinename.obip;
fi

then, you need to create a crontab job like the following line (say every 30 minutes):

# m h  dom mon dow   command
0,30 * * * * /home/yourusername/sendipout.sh

node.js server part

first of all, node.js and other related stuff need to be installed on your vm (say our vm is "debian based" linux server kind of stuff).

apt install nodejs npm;
npm install express pug node-watch

then, please git clone this repository into your vm, and run it, it should be listening on port 21180.

cd /the/directory/that/you/just/cloned/it/into/;
node app.js

and please notice, again, that, you should change some codes in app.js, such as putting the reall path, like "/home/yourvmusername/.yourmachinename.obip", into array fn, if you know what i mean.

About

using crontab to polling the ip (using curl to get the public ip, using scp to send it).using node.js to watch the files that hold the ips and show the very freshed ones.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published