Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import csv
  2. import os
  3. import psycopg2
  4.  
  5. path = 'custom_asn.csv'
  6.  
  7.  
  8. try:
  9. connection = psycopg2.connect(user = "scrutremote",
  10. password = "admin",
  11. host = "127.0.0.1",
  12. port = "5432",
  13. database = "plixer")
  14. cursor = connection.cursor()
  15. #delete old table.
  16. cursor.execute("""DELETE from plixer.asn_custom;""")
  17. connection.commit()
  18. cursor.close()
  19. connection.close()
  20.  
  21. except (Exception, psycopg2.Error) as error :
  22. print ("Error while connecting to PostgreSQL", error)
  23.  
  24.  
  25. with open(path, 'r', encoding='utf-8', errors='ignore') as infile, open('/home/plixer/scrutinizer/files/custom_asn.import', 'w') as outfile:
  26. inputs = csv.reader(infile)
  27. output = csv.writer(outfile)
  28. #convert kinner csv - > one ready for import.
  29. for row in inputs:
  30. as_number = row[1]
  31. as_name = row[1] + ' ' + row[2]
  32. as_description = 'Covance ASN'
  33. as_subnet = row[3] + '/' + row[4]
  34. output.writerow([as_number,as_name,as_description,as_subnet])
  35.  
  36. #run import
  37. os.system("scrut_util.exe /home/plixer/scrutinizer/bin/scrut_util.exe --import asns")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement