AutoHotkey Community

It is currently May 27th, 2012, 12:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: December 9th, 2009, 5:25 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
I make this small tool as an anti-theft protection.
The script starts with the PC, try to get the external IP and send an email with the pc-name and IP-number.
It does this only if the IP changes. That's all.
As you can see, it works only if the thief starts your notebook, if he login and if he is online at this moment.
Only a really dumb thief could be caught this way, but who knows.

You should compile the script with nodecompile to protect your email.


You've to do:
    Change the email params.
    Compile it with nodecompile.
    Put it somewhere on the PC.
    Start it once.

Now you get an email after PC start, including the IP-number and PC name.

Tested with Win7.


Hopefully you never need this.

Code:
/*
protect your hardware

The script starts with the PC, try to get the external IP and send an email with the pc-name and IP-number.
It does this only if the IP changes. For the autostart it writes to registry.

You've to add your email data and then you should compile the script with nodecompile.

To use it, put the compiled Exe somewhere and start it once. Then you get periodically emails with
the external IP.

author: haichen 2009

used code:
--------------
cdo com - email delivery
author sean
http://www.autohotkey.com/forum/viewtopic.php?t=39797

com - standard library
code from sean
http://www.autohotkey.com/forum/viewtopic.php?p=146242#146242

URLDownloadToVar
from Olfen
http://www.autohotkey.com/forum/viewtopic.php?p=64230#64230

Retrieve "external IP Adress"
from SKAN
http://www.autohotkey.com/forum/viewtopic.php?p=42420#42420

IP-number pattern
http://regexlib.com

Get your extern IP
http://Checkip.dyndns.org/

This script:
http://www.autohotkey.com/forum/viewtopic.php?p=316526#316526

*/
#NoTrayIcon

; filename where to store the IP-number
tmp=m189hhj.tmp
TmpFile=%WinDir%\TEMP\%tmp%

; get your external IP
MyExternalIPText := UrlDownloadToVar("http://Checkip.dyndns.org/")
pattern=\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b
FoundPos := RegExMatch(MyExternalIPText, pattern, IP)
;-----------------------------------------------------------------
; if you install the program as a service you should comment this block
; Autostart
regname=mip
If a_isCompiled
  RegWrite,REG_SZ,HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Run,%regname%,"%A_ScriptDir%\%A_ScriptName%"
;-----------------------------------------------------------------
; change your email params here
sFrom     := "mymail@googlemail.com"
sTo       := "mymail@googlemail.com"
sSubject  := "changed IP adress"
sBody     = External IP of  %A_ComputerName%: %ip%
sAttach   := ;"Path_Of_Attachment" ; can add Multiple attachments, the Delimiter is |

sServer   := "smtp.gmail.com" ; specify your SMTP server
nPort     := 465 ; 25
bTLS      := True ; False
nSend     := 2   ; cdoSendUsingPort
nAuth     := 1   ; cdoBasic
sUsername := "mymail@googlemail.com"
sPassword := "mymailpassword"
;-----------------------------------------------------------------

FileReadLine,oldIP,%TmpFile%,1

If ((ip<>"") and (oldIP <> ip) )
{
  FileDelete,%TmpFile%
  FileAppend, %IP%`n ,%TmpFile%

  COM_Init()
  pmsg :=   COM_CreateObject("CDO.Message")
  pcfg :=   COM_Invoke(pmsg, "Configuration")
  pfld :=   COM_Invoke(pcfg, "Fields")

  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/Sendusing", nSend)
  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 60)
  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserver", sServer)
  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserverport", nPort)
  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpusessl", bTLS)
  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", nAuth)
  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/Sendusername", sUsername)
  COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/SendPassword", sPassword)
  COM_Invoke(pfld, "Update")

  COM_Invoke(pmsg, "From", sFrom)
  COM_Invoke(pmsg, "To", sTo)
  COM_Invoke(pmsg, "Subject", sSubject)
  COM_Invoke(pmsg, "TextBody", sBody)
  Loop, Parse, sAttach, |, %A_Space%%A_Tab%
    COM_Invoke(pmsg, "AddAttachment", A_LoopField)
  COM_Invoke(pmsg, "Send")

  COM_Release(pfld)
  COM_Release(pcfg)
  COM_Release(pmsg)
  COM_Term()
}
Return

;functions

UrlDownloadToVar(URL, Proxy="", ProxyBypass="") {
    AutoTrim, Off
    hModule := DllCall("LoadLibrary", "str", "wininet.dll")

    If (Proxy != "")
      AccessType=3
    Else
      AccessType=1
    ;INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
    ;INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
    ;INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
    ;INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS

    io_hInternet := DllCall("wininet\InternetOpenA"
            , "str", "" ;lpszAgent
            , "uint", AccessType
            , "str", Proxy
            , "str", ProxyBypass
            , "uint", 0) ;dwFlags

    iou := DllCall("wininet\InternetOpenUrlA"
            , "uint", io_hInternet
            , "str", url
            , "str", "" ;lpszHeaders
            , "uint", 0 ;dwHeadersLength
            , "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
            , "uint", 0) ;dwContext

    If (ErrorLevel != 0 or iou = 0) {
      DllCall("FreeLibrary", "uint", hModule)
      Return 0
    }

    VarSetCapacity(buffer, 512, 0)
    VarSetCapacity(NumberOfBytesRead, 4, 0)
    Loop
    {
      irf := DllCall("wininet\InternetReadFile", "uint", iou, "uint", &buffer, "uint", 512, "uint", &NumberOfBytesRead)
      NOBR = 0
      Loop 4  ; Build the Integer by adding up its bytes. - ExtractInteger
        NOBR += *(&NumberOfBytesRead + A_Index-1) << 8*(A_Index-1)
      IfEqual, NOBR, 0, Break
      ;BytesReadTotal += NOBR
      DllCall("lstrcpy", "str", buffer, "uint", &buffer)
      res = %res%%buffer%
    }
    StringTrimRight, res, res, 2

    DllCall("wininet\InternetCloseHandle",  "uint", iou)
    DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
    DllCall("FreeLibrary", "uint", hModule)
    AutoTrim, on
    Return, res
  }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2009, 6:21 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
Quote:
Only a really dumb thief could be caught this way, but who knows.


This is actually a good idea, but you are correct that it is not fool proof.


I don't know about your internet company, but who I subscribe too, we have 'Dynamic' IPs. The modem is issued a new IP every week or so. (I don't know why, they state security reasons)

Granted, if you are using a router, your IP will remain the same 192.169.x.x generally, but what if they thief has the same router IP as yours? Say you have a Netgear router and so does he, both Router IPs should be the same.


If you have a Static IP address this would be great.


A different idea, you may want to consider is the MAC. MAC id's are tied to modems, so even if/whem my IP changes my Modem MAC will still be 00:00:00:00:00:0a ect If the script notices that the laptop is plugged into a different modem/MAC, may be more accurate


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2009, 6:29 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
I use http://Checkip.dyndns.org/ to get the external IP.
That's the ip your provider gives you.

Check it out!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2009, 6:39 pm 
Offline

Joined: December 24th, 2008, 3:25 am
Posts: 1401
Location: :noitacoL
haichen wrote:
I use http://Checkip.dyndns.org/ to get the external IP.
That's the ip your provider gives you.

Check it out!


Sorry. It was my understanding that the external IP was the one that was dynamic/changes.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2009, 6:44 pm 
Online

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
Carcophan wrote:
haichen wrote:
I use http://Checkip.dyndns.org/ to get the external IP.
That's the ip your provider gives you.

Check it out!


Sorry. It was my understanding that the external IP was the one that was dynamic/changes.

it is. mine changes almost daily.

it is he who is lost.

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Last edited by tidbit on December 9th, 2009, 6:48 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2009, 6:47 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
The external IP change with time but nevertheless your adress can be found.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2009, 9:02 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
most importantly with the external IP you can track down the ISP and find out where the IP connected from at the time with a location the Police may have cause for a search

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 1:38 am 
Even better would be if your laptop has a GPS chip, then you can use google and give the cops the stinkin' house number!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2009, 5:28 am 
Offline

Joined: September 28th, 2009, 4:32 am
Posts: 86
I was thinking.... notepad can have gps installed. So it's easy to track the location, but not easy to protect the sensitive data from being extracted.
So maybe you can write the script to self-destruct all sensitive data on HDD, once un-authorized access is detected. Just an idea.

_________________
TypingAid autocompletion program made with AHK.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Cristi®, tidbit and 52 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group