Procedure to get Browser History Report to your Email ID

Please use the script to get an Email Report of Browsing History of all popular browsers

Note:
Run the procedure as a System User

If you want to use your own sender configuration then change the following lines of code.

msgbody='Hi,
Please find the attachment for the Browsing History in CSV file format.

Thank you.'
emailto=['youremail@domain.com']
emailfrom='testcomodomail1@gmail.com'
password='C0m0d0@123'
smtpserver='smtp.gmail.com'
port=587

or if you want to use the existing (ours) sender configuration then you have to change only the following line of code

emailto=['youremail@domain.com']

Limitation:
Collects data from following browsers only

  • Internet Explorer (Version 4.00 and greater)
  • Mozilla Firefox (Version 3.00 and greater)
  • Microsoft Edge
  • Google Chrome
  • Safari
  • Opera (Version 15 or later, which is based on Chrome Web browser)
Complete Script:
msgbody='Hi,
Please find the attachment for the Browsing History in CSV file format.

Thank you.'
emailto=['yourmailid@domain.com']
emailfrom='testcomodomail1@gmail.com'
password='C0m0d0@123'
smtpserver='smtp.gmail.com'
port=587

def computername():
    import os
    return os.environ['COMPUTERNAME']

def ipaddress():
    import socket
    return socket.gethostbyname(socket.gethostname())

def emailreport(subject, emailto,emailfrom,fileToSend,password,smtpserver,port,msgbody):
    import smtplib
    import mimetypes
    from email.mime.multipart import MIMEMultipart
    from email import encoders
    from email.message import Message
    from email.mime.audio import MIMEAudio
    from email.mime.base import MIMEBase
    from email.mime.image import MIMEImage
    from email.mime.text import MIMEText
    import os
    msg = MIMEMultipart()
    msg["From"] = emailfrom
    msg["To"] = ",".join(emailto)
    msg["Subject"] = subject
    msg.preamble = subject
    body = MIMEText(msgbody)
    msg.attach(body)       
    with open(fileToSend, 'rb') as fp:
        record = MIMEBase('text', 'octet-stream')
        record.set_payload(fp.read())
        encoders.encode_base64(record)
        record.add_header('Content-Disposition', 'attachment', filename=os.path.basename(fileToSend))
        msg.attach(record)
    try:
        server = smtplib.SMTP(smtpserver,port)
        server.ehlo()
        server.starttls()
        server.login(emailfrom, password)
        server.sendmail(emailfrom, emailto, msg.as_string())
        server.quit()
        return "the email report has been sent to "+msg["To"]
    except Exception as e:
        return e

def ecmd(CMD, r=False):
    import ctypes
    class disable_file_system_redirection:
        _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
        _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
        def __enter__(self):
            self.old_value = ctypes.c_long()
            self.success = self._disable(ctypes.byref(self.old_value))
        def __exit__(self, type, value, traceback):
            if self.success:
                self._revert(self.old_value)
    from subprocess import PIPE, Popen
    with disable_file_system_redirection():
        OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
    out, err = OBJ.communicate()
    ret=OBJ.returncode
    if r:
        return ret
    else:            
        if ret==0:
            return out
        else:
            return ret

import os
import urllib2
import zipfile
import shutil

if 'PROGRAMW6432' in os.environ.keys():
    url='http://www.nirsoft.net/utils/browsinghistoryview-x64.zip'
else:
    url='http://www.nirsoft.net/utils/browsinghistoryview.zip'

o=urllib2.urlopen(url)
c=o.code
temp=os.environ['TEMP']
if c==200:
    zf=os.path.join(temp, url.split('/')[-1])
    with open(zf, 'wb') as w:
        w.write(o.read())
##    print zf, 'downloaded'
else:
    print c, 'error with download url'

z=zipfile.ZipFile(zf, 'r')
ep=os.path.join(temp, url.split('/')[-1][:-4])
z.extractall(ep)
z.close()
os.remove(zf)
if os.path.exists(ep):
    pf=os.path.join(ep, 'BrowsingHistoryView.exe')
    if os.path.isfile(pf):
        cf=os.path.join(temp, 'browsinghistory.csv')
        ec=ecmd('"%s" /scomma "%s"'%(pf, cf), r=True)
        if ec==0:
##            print cf, 'report has been created'
            subject=computername()+'::'+ipaddress()+' Browser History Report'
            print emailreport(subject,emailto,emailfrom,cf,password,smtpserver,port,msgbody)
            os.remove(cf)
        else:
            print ec, 'error on report creation'
    shutil.rmtree(ep)
else:
    print 'error on extraction ...'

Script to Import:

Sample Output:
Execution Log -

Email Notification -

Email Content -

CSV Report (After Downloading) -

Screenshot_1.png

20170512-Imported-Browser-History.json (5.43 KB)

Very awesome Purushothaman, thank you for creating this, works perfectly!

Very Nice. i got most to run with success but a few came back with errors. i run on few test devices.
Data: Traceback (most recent call last):
File “”, line 80, in
File “C:\Program Files\COMODO\Comodo ITSM\lib\os.py”, line 425, in getitem
return self.data[key.upper()]
KeyError: ‘PROGRAMW6432’

Hi @hytekcomputers,

Thanks for letting us know the issue, we will update the script to solve the issue as soon as possible.

Thank you.

Hi @hytekcomputers,

Please check the updated script again, the issue has been fixed.

https://forum.mspconsortium.com/forum/script-library/11151-procedure-to-get-browser-history-report-to-your-email-id#post11151

Thank you.

@Purushothaman

​​​​​​​I am getting an error: File “”, line 114, in
WindowsError: [Error 2] The system cannot find the file specified: ‘C:\Windows\TEMP\browsinghistory.csv’

Hi @BOSS,

We will check the script and let you know the solution, Thank you.

Hi @BOSS,

Please execute the script as system user and let us know the details of execution log to address the issue for Brower History.

Thank you.

20170516-test—bh.json (5.83 KB)

OK, it will be a while, but I will give it a whirl!!! Thanks.

Hi @BOSS,

Please let us know your windows version of your computer, we will check the script on the same version and let you know the status.

For your information, we have checked at Windows 10 Pro, Windows 10 Home, Windows 7 Home and Windows 8.1 Pro and we got the result as ‘Finished Success’ with excepted output.

For your case, we would like to find out the root-cause in order to resolve the issue.

Thank you.

Windows 7 Pro, I will rerun it, is it possible that I forgot to run as system user, and got this error???

I re-ran the script, and it ran, what was weird, was that when it failed, it failed 3 times within 1-2 minutes. I do not remember running it that many times, so I am unsure if something triple triggered, or glitched, or something and caused this issue. I am running it on a couple other systems, and will report back. Thanks for your assistance in this matter.