LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-29-2015, 01:31 PM   #1
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 132

Rep: Reputation: Disabled
Question Script to detect and email IP address?


On my laptop I have a guest account that can be accessed without a password. One reason I did this is so that if my laptop is stolen, the thief can still use it without needing to wipe it and reinstall.

I would like to set up a script of some sort that will silently email me the computer's IP address whenever the guest account connects to the internet. Is there a way to do this?
 
Old 10-29-2015, 06:05 PM   #2
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 22.04 LTS
Posts: 240

Rep: Reputation: 67
Script to detect and email IP address?

Just let it send an empty email. The IP will be in the header. Or install something like "Prey".
 
Old 10-29-2015, 06:49 PM   #3
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
I assume you only want this to occur if the guest account logs in.
In the desktop environment, can you setup startup scripts?

If you ran something like this as a startup script for the guest account, it probably would do what you want.

Code:
while true; do ping -c1 google.com &> /dev/null && curl myexternalip.com/raw | mail -s 'Guest Account Used' email@domain; sleep 60; done
If you wanted to, you could probably spend some more time making it more "hidden" like after sending a email, not sending another one until the external ip changes and such varying the times you attempt to connect. You could also do a SSID scan and email that info as well.

Last edited by Sefyir; 10-29-2015 at 06:57 PM.
 
Old 10-29-2015, 08:56 PM   #4
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 132

Original Poster
Rep: Reputation: Disabled
I'm still not completely sure about how to properly do scripts anyway. I know the basics of bash and I'm teaching myself Python, but I'm not sure how to set up a script file for what you just showed me. My desktop does have a "startup programs" option that I can point to a file. However, scripts generally need some equivalent of "#!/bin/bash" or "#!/usr/bin/python" in the first line, so what would I use in this case?
 
Old 10-29-2015, 09:47 PM   #5
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
#!/bin/bash refers to what program should be invoking the commands.
In this case, it would be bash

So something like

Code:
#!/bin/bash

while true; do ping -c1 google.com &> /dev/null && curl myexternalip.com/raw | mail -s 'Guest Account Used' email@domain; sleep 60; done
I would definitely do some tests before assuming it works as it's untested atm.

edit: bolded parts that need to be changed.

Last edited by Sefyir; 10-30-2015 at 07:19 PM.
 
Old 10-30-2015, 12:01 PM   #6
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 132

Original Poster
Rep: Reputation: Disabled
What's the /dev/null bit? Is that something I have to change to something specific to my system?
 
Old 10-30-2015, 12:28 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
> /dev/null redirects standard output (stdout) to /dev/null, which discards it.
Basically suppresses the standard out (screen/console) to a "bit bucket" that discards it.

Test it?

Code:
ls -al > /dev/null

Last edited by Habitual; 10-30-2015 at 12:29 PM.
 
Old 10-30-2015, 01:02 PM   #8
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 132

Original Poster
Rep: Reputation: Disabled
I ran it and nothing seemed to happen. And yes, I did insert my real email address. ;P
 
Old 10-30-2015, 01:09 PM   #9
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 132

Original Poster
Rep: Reputation: Disabled
Wait ... that thing has an infinite while loop in it. Is it going to keep running until I reboot?
 
Old 10-30-2015, 01:10 PM   #10
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,679

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
This will be non-trivial to do andwill require either your real email login and password, one you create for the purpose or a known-good "open relay" in order to send an email at all. Personally, I would have the device make an http request to a web server I control, on a non-standard post, so that the logs of that web server can be checked for the IP address.
Heck, one could do away with having an actual web server and just have either an open port. Or, more securely, have it do something that would flag for easy identification in home router or other firewall logs.
(I may try this myself, come to think of it, just for fun)
 
Old 10-30-2015, 01:21 PM   #11
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 132

Original Poster
Rep: Reputation: Disabled
"This will be non-trivial" Yes; I was surprised when the other guy (or gal) just gave me a single line of code.

Ok, I know little about networking, so I'm not sure exactly what most of what you said means. Let's start with "have it do something that would flag for easy identification in home router". Do you mean have it send something specifically to my home router?
 
Old 10-30-2015, 01:38 PM   #12
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,679

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by Flexico View Post
"This will be non-trivial" Yes; I was surprised when the other guy (or gal) just gave me a single line of code.

Ok, I know little about networking, so I'm not sure exactly what most of what you said means. Let's start with "have it do something that would flag for easy identification in home router". Do you mean have it send something specifically to my home router?
Yes both bearing in mind that home routers change IP address sometimes and, if they don't, the bad guy has just done something to your home router.
Taking the above into account the most simple thing I could think of would be to do something like enable loggin on a home router then have the laptop use nmap to scan ports 1970 to 2015 on the home IP address on boot. Perfectly harmless but will result in the logs of the home router logging the IP address that the scans come from against scans of that range.
I hope others may have better ideas as I'm not sure I would use the above "in anger" but I feel that something relying only upon the laptop having an internet connection rather than things like email is probably better.
You could also just sign up for a free dynamic DNS service (I'll leave you to google it as I can't link etc. so well typing on my phone) then use the dynamic DNS client on the laptop and check the website for updates.

Last edited by 273; 10-30-2015 at 01:46 PM. Reason: Typo's and confusing text corrected (a bit at least).
 
Old 10-30-2015, 02:53 PM   #13
Flexico
Member
 
Registered: Aug 2015
Distribution: Mint MATE
Posts: 132

Original Poster
Rep: Reputation: Disabled
I do have Teamviewer installed on both computers, but that would require me to be on my computer at the same time the thief is, and if I used the remote-control feature to open a web browser and google "what's my ip" (which was my original plan) that would be rather conspicuous. Perhaps there's some kind of feature in Teamviewer that I don't know about that could automatically do it?
 
Old 10-30-2015, 07:18 PM   #14
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Quote:
Wait ... that thing has an infinite while loop in it. Is it going to keep running until I reboot?
Yup

Quote:
Yes; I was surprised when the other guy (or gal) just gave me a single line of code.
I ran it and nothing seemed to happen. And yes, I did insert my real email address. ;P
It's pretty simple in its function.
If it can ping google.com, then send you a email based on the results of curling myexternalip.com/raw, which is the computers current external ip address. sleep for 60 seconds, then loop again.
If you only want it to do it once, upon connection upon boot, that would be fairly easy. Maybe use some kind of a until loop

Of course, this assumes you can send a email with mail. You can use guides listed here or or here to help setup mail. You can use a relay, but you should be able to just send a email. You will likely need a mail server setup to do this.


Sorry I didn't explain it thoroughly, dumping code and not explaining doesn't help you much.

Quote:
This will be non-trivial to do
I wouldn't consider it that difficult, it's a detect and send email. Since it's only run on the guest account, there should be no false triggers.

_____

Edit:

Quote:
I do have Teamviewer installed on both computers, but that would require me to be on my computer at the same time the thief is, and if I used the remote-control feature to open a web browser and google "what's my ip" (which was my original plan) that would be rather conspicuous. Perhaps there's some kind of feature in Teamviewer that I don't know about that could automatically do it?
To be honest, a locally forwarded port to a virtual private server upon the guest user logging in and connecting to the network would be pretty cool since it would give you ssh access to the computer... no matter where the thief took it. Something that occurred to me last night lol.
I was messing around with it for a bit and stumbled when it required root access to port <1024 ports (22) but having root access could give you the ability to scan their environment, see what they're doing, grab images from a camera... etc...
You could even run curl myexternalip.com/raw and find your external ip. Much less obvious then doing it over the graphical user interface in classic spy style hacker takeover :P

Last edited by Sefyir; 10-30-2015 at 07:27 PM.
 
Old 10-30-2015, 07:32 PM   #15
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,679

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by Sefyir View Post
I wouldn't consider it that difficult, it's a detect and send email. Since it's only run on the guest account, false triggers would be difficult since it would only occur when it's the guest user logged in.
The triggering of the script is trivial, the detection of the relevant IP address less so as it requires connecting to a source of that IP and parsing it, the sending the email part though is tough, unless you can do the following:
Write a script which will send an email from the command line in Linux from any internet connection anywhere in the world without requiring a known SMTP server and credentials for that server. Bonus points if you can get away from using DNS.
If you can't, then I would argue that the best approach is to have the script on the stolen device contact a known machine via another method. If you can, then you've helped the OP and put me in my place with your script-fu .

In fact, I'm beginning to wonder whether the simplest and possibly most anonymous method* is to simply register a free dynamic DNS server and have the (potentially stolen) laptop run a script to update its IP address with that server whenever it is online. That way if the laptop goes missing the dynamic DNS service will show the relevant IP, heck, you could just reverse DNS it.

*Your guest need not know your email credentials nor any IP addresses associated with you other than the last one stored to compare with the dynamic DNS entry but this would be cleared as soon as it was changed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
run a shell script/cronjob when any email arrive to specific email address ikillu Linux - General 3 05-30-2009 08:18 AM
Using a script to send a file to email address kopite Programming 3 06-17-2008 03:21 AM
Script to check IP address and send to an email kbrajesh Linux - Networking 4 02-08-2007 03:13 AM
script to relay the data in the fields to my email address generalachoo Programming 4 08-25-2006 07:54 AM
bash script to detect scsi address at boot ewto Programming 2 10-20-2003 02:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration