Archive for category MS Junk

The servers in our DMZ do not have any access to the outside world. Getting Symantec dat files onto the DMZ AV server was kind of a pain. I would manually download the latest file (when I remembered) and then copy it to the correct directory on the server. I was getting kind of tired of manually doing this and add to that it was only happening about 2 times a month. Today I decided that I would write a script in python to take care of getting the correct file and moving it to the right location for me.  I have not set it up as a scheduled task yet but I may in the future. Here is what I came up with:

Disclaimer: I know that this may not be the best code written. I am still learning so please make comments that could improve on what is here. Thanks.

#!/usr/bin/env python

import datetime
from ftplib import FTP
import shutil, os

### Config stuff ###
# FTP site to connect to
ftpsite = ''

# Directory where the files are stored on the FTP server
directory = 'AVDEFS/symantec_antivirus_corp/xdb/'

# Set a variable for todays date like Feb 03 to match to
today ="%b %d")

# Array to hold the directory listing of the remote server
data = []

# Set the directory on the DMZ AV server to copy to
destDir = r'\\SomeRemoteAvServer\RemoteDir'

def handleDownload(block):
    print ".",

# Find the file that matches todays date
def getFilename(data):
    for line in data:
        perms, x, y, z, size, month, day, time, filename = line.split()
        if len(day) == 1:
            day = '0' + day
        timestamp = month + ' ' + day
        if timestamp == today:
            return filename

def compareFileSize(filename,destFile):
    Compares src file to destFile to see if they are the same size.
    if os.path.getsize(filename) == os.path.getsize(destFile):
        return 1
        return 0

# Open a connection to the FTP server
ftp = FTP(ftpsite)

# Log in as anonymous
print 'Logging in.'
print ftp.login()

# Change to the directory where the files are stored

# Get a directory listing

# Get the file that matches todays date from the directory listing
filename = getFilename(data)

print 'Opening local file ' + filename
file = open(filename, 'wb')

# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)

# Clean up time
# Close the local file
print 'Closing file ' + filename

# Disconnect from the FTP server
print 'Closing FTP connection'
print ftp.close()

destFile = os.path.join(destDir,filename)

# Now copy the file to the AV server in the DMZ if it does not already exist
# then remove it from the local system.
if os.path.isfile(destFile):
    print 'The file %s is already on the server.' % filename
    print 'Copying the file to %s' % destDir
    shutil.copy2(filename, destDir)
    # Compare the two files to make sure they copied correctly
    if compareFileSize(filename, destFile):
        print 'The file looks to have copied fine. Deleting the local copy now.'
        print 'Something seems to have gone wrong. The file did not copy correctly to %s' % destDir


IIS ODBC Logging (the way that works)

This post is mainly for my benefit (it may help others too).

I was asked at work to turn on IIS logging to an ODBC connection. I did a little Googleing and found this site Microsoft recommends that you do not do this though because on a heavily used site it can cause performance issues. They appear to be so against the idea of doing it that the script that they provide in %Windir%\System32\Inetsrv does not work. The rest of the steps on that site are correct though. Here is the script that I used to create the table that will actually allow the logging to work:

CREATE TABLE [InternetLog] (
	[LogTime] [datetime] NOT NULL ,
	[ClientHost] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[service] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[machine] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[serverip] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[processingtime] [int] NULL ,
	[bytesrecvd] [int] NULL ,
	[bytessent] [int] NULL ,
	[servicestatus] [int] NULL ,
	[win32status] [int] NULL ,
	[operation] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[target] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[parameters] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[username] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

With any luck we will just turn this on when it is needed and not leave it running all the time.


Leave a comment