atrueresistance
atrueresistance

Reputation: 1368

first python program need a bit of help writing to file

I have a small program that I'm trying to create to get ip addresses from an sqlite db and run the whois command on and write it to a data file.

import sqlite3
import os
v_path = os.path.abspath('') 
v_db = os.path.abspath("../")+"/logsql.sqlite"
v_ip = v_path+"/Whois.Resources/Who.IP.txt"
print v_ip
try:
    f1 = open(v_db)
    f2 = open(v_ip, "w")
    conn = sqlite3.connect(v_db)
    c = conn.cursor()
    c.execute("select remote_host from connections group by remote_host;")
    for row in c:
        print row
        #p.write("sts")
    c.close()   
    f1.close()
    f2.close()
except IOError as e:
   print 'Oh dear, shit just hit the fan.'

The output looks like this

bash$ python WhoIs.Program.py 
/Users/frankwiebenga/Documents/Spring 2012/Malware/WhoIs/Whois.Resources/Who.IP.txt
Oh dear, shit just hit the fan.

The issue is opening v_ip, the v_db opens fine. The file is there

bash$ pwd
/Users/frankwiebenga/Documents/Spring 2012/Malware/WhoIs/WhoIs.Resources
bash$ ls
Who.IP.txt
frank-wiebengas-macbook-pro:WhoIs.Resources frankwiebenga$

The directory structure is

logsql WhoIs{directory}
____________
WhoIs.Program.py WhoIs.Resources{directory}
____________
Who.IP.txt

Upvotes: 1

Views: 138

Answers (1)

Mark Ransom
Mark Ransom

Reputation: 308121

Whois.Resources should be WhoIs.Resources. Linux is case sensitive.

P.S. Thanks for including enough information in your question to figure this out. It's rare for that to happen.

Upvotes: 2

Related Questions