On May 24, 2009, at 11:18 PM, Paras K. wrote:

Hello,

I came across your answer / assistance on the IP range.

I recommend looking at the ipaddr library:

http://svn.python.org/projects/python/trunk/Lib/ipaddr.py

There is some Sphinx documentation with the python 2.7 docs and some on the original google code page.

I am fairly new to the python world of programming. However, up to this point I have always been able to get my programs to work by reading the books or following the guides I find through google.com

Here is what I have to do:

I have to read a number of cvs files into 1 large file. (I have been able to get that done through a perl script). But after I get it into a large cvs file, I need to be able to look at each row and see if it falls within a specific IP ranges.

IP Ranges:

162.x.x.x
151.130.x.x
145.x.x.x

These are just some examples of the IP ranges.

The csv file has data like below:

63.145.40.32
Gnutella File Search
14
5/15/2009 0:48
151.40.133.25
Gnutella File Search
14
5/14/2009 16:21
145.133.19.147
BitTorrent Client Activity
13
5/14/2009 19:20

Here is my source code so far:

import sys
import win32api
import win32ui
import shutil
import string
import os
import os.path
import csv

#Global Variables
P2Pfiles = []


#still in the development process -- where to get the files from
#right now the location is C:\P2P
def getp2preportdestion():
win32ui.MessageBox('Welcome to P2P Reporting.\nThis script is designed to aid in the P2P reporting. \n\nThe locations of P2P Reports should be in C:\P2P \n\nWith no subdirectories.\n\n\n\n \nVersion 1.0 - \n\nPress "OK" to continue with this script.')
    #p2pdrive=raw_input("Enter the drive letter:  ")
    #p2pdir=raw_input("Enter the directory name:  ")
    #p2preport = p2pdrive +':\\'+p2pdir+'/'
    p2preport = 'C://P2P\\'
    return p2preport





#Main Program

#Get location of directories
p2ploc = getp2preportdestion()

#Checking to make sure directory is there.
if os.path.exists(p2ploc):
    if os.path.isfile(p2ploc +'/p2pmerge.csv'):
win32ui.MessageBox('Merge File exists..will continue with program')
    else:
win32ui.MessageBox('Merge File does not exists, script will exit. Please run the perl script first.')
         exit()
else:
win32ui.MessageBox('The C:\P2P directory does not exists.\n \nPlease create and copy all the files there.\nThen re-run this script')
       exit()

reader = csv.reader(open('C://P2P/p2pmerge.csv', "rb"))
p2pwriter = csv.writer(open('C://P2P\P2PMerge4.csv', "wb"))
for row in reader:
    p2pwriter.writerow([row])

win32ui.MessageBox('I am here')


Any assistance will be greatly appricated!!!

Thanx,
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to