You are not logged in.

#1 2011-04-25 13:25:23

scarletxfi
Member
From: Australia
Registered: 2010-04-19
Posts: 105

remote laptop location

I've written a small bash script that in theory will result in the IP address of a remote laptop.
in other words if you want to keep tab on your laptop, this script maybe useful for finding out where you're laptop is (ie if stolen or something)
it should (can) be run as a deamon in the background so whenever the computer turns on it'll turn run.
scirpt assumes passwordless ssh access (for example: http://www.linuxproblem.org/art_9.html) for a basic user.

to get the important stuff out of the way:
* THERE IS NO GUARANTEE THIS WILL WORK
* I AM NOT RESPONSIBLE FOR ANY DAMAGE AS A RESULT OF THIS SCRIPT

now that that is out of the way....


#!/bin/bash

#script that records login date and IP address of login and sends to remote server 
#written by: shavi, shavi_at_shavi.net

REMOTE_SERVER="SERVER" #change here for remote server
REMOTE_USER="remote" #change gere here for remote user
DATE=$(date)
IP=$(ifconfig | grep addr)
ip_locator=$(wget http://www.ip2location.com/ib2/ -O /tmp/ip 2> /dev/null)
ip_location=$(cat /tmp/ip | grep "Your IP")
info=$DATE.$IP.$ip_location
browser="links" #change here for browser
browser_on='ps -no-headers -C{$browser} | wc -l'
browser_flag='0'

while (true)
do
    echo  "$info" > /tmp/login_info #write info to a file
    if ( (ping -c1 -w 5 www.google.com > /dev/null) || browser_flag=='1') #if google responds or browser open
    then
            browser_flag='0' #clear browser_flag
            cat /tmp/login_info | ssh $REMOTE_USER@$REMOTE_SERVER "cat > ~/LAPTOP_LOGIN_INFO" #login and dump info at home, exit
            if [ -e /tmp/login_info ] #cleaning up locally
                then
                    rm /tmp/login_info
            fi
            #exit; #exit straight away if connection is up
    else #or wait to see if browser is on (was thiknig of ISR, but i don't think that is possible)
        sleep 5m #login grace time, approximate time to login and start browsing 
        if [ ${browser_on} -gt 1 ];
        then
            browser_flag='1' #browser_flag on, browser is ope, go to begining and grab info, then see if google pings google then send info again
        fi
    fi
done

note: this is my attempt at begining bash scripting ..


suggestions\tips\comments will be greatly appreciated...

Last edited by scarletxfi (2011-04-25 13:27:15)

Offline

Board footer

Powered by FluxBB