Python cx_Oracle.makedsn() Examples

The following are 26 code examples of cx_Oracle.makedsn(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cx_Oracle , or try the search function .
Example #1
Source File: patator.py    From patator with GNU General Public License v2.0 9 votes vote down vote up
def execute(self, host, port='1521', user='', password='', sid='', service_name=''):

    if sid:
      dsn = cx_Oracle.makedsn(host=host, port=port, sid=sid)
    elif service_name:
      dsn = cx_Oracle.makedsn(host=host, port=port, service_name=service_name)
    else:
      raise ValueError('Options sid and service_name cannot be both empty')

    try:
      with Timing() as timing:
        fp = cx_Oracle.connect(user, password, dsn, threaded=True)

      code, mesg = '0', fp.version

    except cx_Oracle.DatabaseError as e:
      code, mesg = e.args[0].message[:-1].split(': ', 1)

    return self.Response(code, mesg, timing)

# }}}

# PostgreSQL {{{ 
Example #2
Source File: connector.py    From EasY_HaCk with Apache License 2.0 6 votes vote down vote up
def connect(self):
        self.initConnection()
        self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
        self.__dsn = utf8encode(self.__dsn)
        self.user = utf8encode(self.user)
        self.password = utf8encode(self.password)

        try:
            self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
            logger.info("successfully connected as SYSDBA")
        except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), ex:
            if "Oracle Client library" in str(ex):
                msg = re.sub(r"DPI-\d+:\s+", "", str(ex))
                msg = re.sub(r': ("[^"]+")', r" (\g<1>)", msg)
                msg = re.sub(r". See (http[^ ]+)", r'. See "\g<1>"', msg)
                raise SqlmapConnectionException(msg)

            try:
                self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
            except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
                raise SqlmapConnectionException(msg) 
Example #3
Source File: patator_ext.py    From project-black with GNU General Public License v2.0 6 votes vote down vote up
def execute(self, host, port='1521', user='', password='', sid='', service_name=''):

    if sid:
      dsn = cx_Oracle.makedsn(host=host, port=port, sid=sid)
    elif service_name:
      dsn = cx_Oracle.makedsn(host=host, port=port, service_name=service_name)
    else:
      raise ValueError('Options sid and service_name cannot be both empty')

    try:
      with Timing() as timing:
        fp = cx_Oracle.connect(user, password, dsn, threaded=True)

      code, mesg = '0', fp.version

    except cx_Oracle.DatabaseError as e:
      code, mesg = e.args[0].message[:-1].split(': ', 1)

    return self.Response(code, mesg, timing)

# }}}

# PostgreSQL {{{ 
Example #4
Source File: base.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def _dsn(self):
        settings_dict = self.settings_dict
        if not settings_dict['HOST'].strip():
            settings_dict['HOST'] = 'localhost'
        if settings_dict['PORT']:
            return Database.makedsn(settings_dict['HOST'], int(settings_dict['PORT']), settings_dict['NAME'])
        return settings_dict['NAME'] 
Example #5
Source File: Database_Oracle.py    From AssmentToolss with GNU General Public License v3.0 5 votes vote down vote up
def check_statue(self):
        """
        @函数方法:检测错误
        :return: 
        """
        self.data = self.conlist
        try:
            tns_name = cx_Oracle.makedsn(self.conlist[2], self.conlist[3], "%s"%self.xe)
            cx_Oracle.connect(self.conlist[0], self.conlist[1], tns_name)
            return (10086, 'access')
        except Exception as e:
            return e 
Example #6
Source File: Database_Oracle.py    From AssmentToolss with GNU General Public License v3.0 5 votes vote down vote up
def conn_oracle(self):
        self.data = self.conlist
        try:
            tns_name = cx_Oracle.makedsn(self.conlist[2], self.conlist[3], "%s"%self.xe)
            db = cx_Oracle.connect(self.conlist[0],self.conlist[1], tns_name)
            return db
        except:
            self.col.printGreen(u"warning!!!!!!!!!!!!!!!!!!!\n程序出错!\n")
            print "\n"
            self.col.printRed(u"脚本连接服务器失败 ,请检查的你的用户名以及密码。或者是否数据库开启权限外链!")
            sys.exit() 
Example #7
Source File: oracle.py    From Archery with Apache License 2.0 5 votes vote down vote up
def get_connection(self, db_name=None):
        if self.conn:
            return self.conn
        if self.sid:
            dsn = cx_Oracle.makedsn(self.host, self.port, self.sid)
            self.conn = cx_Oracle.connect(self.user, self.password, dsn=dsn, encoding="UTF-8", nencoding="UTF-8")
        elif self.service_name:
            dsn = cx_Oracle.makedsn(self.host, self.port, service_name=self.service_name)
            self.conn = cx_Oracle.connect(self.user, self.password, dsn=dsn, encoding="UTF-8", nencoding="UTF-8")
        else:
            raise ValueError('sid 和 dsn 均未填写, 请联系管理页补充该实例配置.')
        return self.conn 
Example #8
Source File: db.py    From cosa-nostra with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **keywords): 
        import cx_Oracle as db 
        if 'pw' in keywords: 
            keywords['password'] = keywords.pop('pw') 

        #@@ TODO: use db.makedsn if host, port is specified 
        keywords['dsn'] = keywords.pop('db') 
        self.dbname = 'oracle' 
        db.paramstyle = 'numeric' 
        self.paramstyle = db.paramstyle

        # oracle doesn't support pooling 
        keywords.pop('pooling', None) 
        DB.__init__(self, db, keywords) 
Example #9
Source File: db.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, **keywords): 
        import cx_Oracle as db 
        if 'pw' in keywords: 
            keywords['password'] = keywords.pop('pw') 

        #@@ TODO: use db.makedsn if host, port is specified 
        keywords['dsn'] = keywords.pop('db') 
        self.dbname = 'oracle' 
        db.paramstyle = 'numeric' 
        self.paramstyle = db.paramstyle

        # oracle doesn't support pooling 
        keywords.pop('pooling', None) 
        DB.__init__(self, db, keywords) 
Example #10
Source File: connector.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
def connect(self):
        self.initConnection()
        self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
        self.__dsn = utf8encode(self.__dsn)
        self.user = utf8encode(self.user)
        self.password = utf8encode(self.password)

        try:
            self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
            logger.info("successfully connected as SYSDBA")
        except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError):
            try:
                self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
            except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
                raise SqlmapConnectionException(msg) 
Example #11
Source File: base.py    From python2017 with MIT License 5 votes vote down vote up
def _connect_string(self):
        settings_dict = self.settings_dict
        if not settings_dict['HOST'].strip():
            settings_dict['HOST'] = 'localhost'
        if settings_dict['PORT']:
            dsn = Database.makedsn(settings_dict['HOST'],
                                   int(settings_dict['PORT']),
                                   settings_dict['NAME'])
        else:
            dsn = settings_dict['NAME']
        return "%s/%s@%s" % (settings_dict['USER'],
                             settings_dict['PASSWORD'], dsn) 
Example #12
Source File: base.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def _connect_string(self):
        settings_dict = self.settings_dict
        if not settings_dict['HOST'].strip():
            settings_dict['HOST'] = 'localhost'
        if settings_dict['PORT'].strip():
            dsn = Database.makedsn(settings_dict['HOST'],
                                   int(settings_dict['PORT']),
                                   settings_dict['NAME'])
        else:
            dsn = settings_dict['NAME']
        return "%s/%s@%s" % (settings_dict['USER'],
                             settings_dict['PASSWORD'], dsn) 
Example #13
Source File: base.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def _connect_string(self):
        settings_dict = self.settings_dict
        if not settings_dict['HOST'].strip():
            settings_dict['HOST'] = 'localhost'
        if settings_dict['PORT'].strip():
            dsn = Database.makedsn(settings_dict['HOST'],
                                   int(settings_dict['PORT']),
                                   settings_dict['NAME'])
        else:
            dsn = settings_dict['NAME']
        return "%s/%s@%s" % (settings_dict['USER'],
                             settings_dict['PASSWORD'], dsn) 
Example #14
Source File: base.py    From python with Apache License 2.0 5 votes vote down vote up
def _connect_string(self):
        settings_dict = self.settings_dict
        if not settings_dict['HOST'].strip():
            settings_dict['HOST'] = 'localhost'
        if settings_dict['PORT']:
            dsn = Database.makedsn(settings_dict['HOST'],
                                   int(settings_dict['PORT']),
                                   settings_dict['NAME'])
        else:
            dsn = settings_dict['NAME']
        return "%s/%s@%s" % (settings_dict['USER'],
                             settings_dict['PASSWORD'], dsn) 
Example #15
Source File: fuzzer.py    From libinjection-fuzzer with MIT License 5 votes vote down vote up
def db_connect(args):
    if args.type == "mysql" or args.type == "mariadb":
        import mysql.connector
        try:
            connection = mysql.connector.connect(
                user=args.user,
                password=args.password,
                database=args.db)
        except mysql.connector.Error as err:
            print(colorize("red", "[ERROR] {}".format(err)))
            return None
    elif args.type == "mssql":
        import pymssql
        try:
            connection = pymssql.connect(server="localhost", database=args.db)
        except pymssql.Error as err:
            print(colorize("red", "[ERROR] {}".format(err)))
            return None
    elif args.type == "pgsql":
        import psycopg2
        try:
            connection = psycopg2.connect(
                "dbname='{}' user='{}' password='{}'".format(
                    args.db, args.user, args.password))
        except psycopg2.Error as err:
            print(colorize("red", "[ERROR] {}".format(err)))
            return None
    elif args.type == "oracle":
        import cx_Oracle
        try:
            connection = cx_Oracle.connect(
                args.user, args.password, cx_Oracle.makedsn(
                    '127.0.0.1', 1521, args.db), mode=cx_Oracle.SYSDBA)
        except cx_Oracle.Error as err:
            print(colorize("red", "[ERROR] {}".format(err)))
            return None

    return connection 
Example #16
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def connect(self):
        self.initConnection()
        self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
        self.__dsn = utf8encode(self.__dsn)
        self.user = utf8encode(self.user)
        self.password = utf8encode(self.password)

        try:
            self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
            logger.info("successfully connected as SYSDBA")
        except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError):
            try:
                self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
            except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
                raise SqlmapConnectionException(msg) 
Example #17
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def connect(self):
        self.initConnection()
        self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
        self.__dsn = utf8encode(self.__dsn)
        self.user = utf8encode(self.user)
        self.password = utf8encode(self.password)

        try:
            self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
            logger.info("successfully connected as SYSDBA")
        except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError):
            try:
                self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
            except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
                raise SqlmapConnectionException(msg) 
Example #18
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def connect(self):
        self.initConnection()
        self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
        self.__dsn = utf8encode(self.__dsn)
        self.user = utf8encode(self.user)
        self.password = utf8encode(self.password)

        try:
            self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
            logger.info("successfully connected as SYSDBA")
        except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError):
            try:
                self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
            except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
                raise SqlmapConnectionException(msg) 
Example #19
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def connect(self):
        self.initConnection()
        self.__dsn = cx_Oracle.makedsn(self.hostname, self.port, self.db)
        self.__dsn = utf8encode(self.__dsn)
        self.user = utf8encode(self.user)
        self.password = utf8encode(self.password)

        try:
            self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
            logger.info("successfully connected as SYSDBA")
        except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError):
            try:
                self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
            except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
                raise SqlmapConnectionException(msg) 
Example #20
Source File: db.py    From Hatkey with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **keywords): 
        import cx_Oracle as db 
        if 'pw' in keywords: 
            keywords['password'] = keywords.pop('pw') 

        #@@ TODO: use db.makedsn if host, port is specified 
        keywords['dsn'] = keywords.pop('db') 
        self.dbname = 'oracle' 
        db.paramstyle = 'numeric' 
        self.paramstyle = db.paramstyle

        # oracle doesn't support pooling 
        keywords.pop('pooling', None) 
        DB.__init__(self, db, keywords) 
Example #21
Source File: test_oracle.py    From airflow with Apache License 2.0 5 votes vote down vote up
def test_get_conn_service_name(self, mock_connect):
        dsn_service_name = {'dsn': 'dsn', 'service_name': 'service_name'}
        self.connection.extra = json.dumps(dsn_service_name)
        self.db_hook.get_conn()
        assert mock_connect.call_count == 1
        args, kwargs = mock_connect.call_args
        self.assertEqual(args, ())
        self.assertEqual(kwargs['dsn'], cx_Oracle.makedsn(
            dsn_service_name['dsn'], self.connection.port,
            service_name=dsn_service_name['service_name'])) 
Example #22
Source File: test_oracle.py    From airflow with Apache License 2.0 5 votes vote down vote up
def test_get_conn_sid(self, mock_connect):
        dsn_sid = {'dsn': 'dsn', 'sid': 'sid'}
        self.connection.extra = json.dumps(dsn_sid)
        self.db_hook.get_conn()
        assert mock_connect.call_count == 1
        args, kwargs = mock_connect.call_args
        self.assertEqual(args, ())
        self.assertEqual(kwargs['dsn'],
                         cx_Oracle.makedsn(dsn_sid['dsn'],
                                           self.connection.port, dsn_sid['sid'])) 
Example #23
Source File: base.py    From bioforum with MIT License 5 votes vote down vote up
def _connect_string(self):
        settings_dict = self.settings_dict
        if not settings_dict['HOST'].strip():
            settings_dict['HOST'] = 'localhost'
        if settings_dict['PORT']:
            dsn = Database.makedsn(settings_dict['HOST'],
                                   int(settings_dict['PORT']),
                                   settings_dict['NAME'])
        else:
            dsn = settings_dict['NAME']
        return "%s/%s@%s" % (settings_dict['USER'],
                             settings_dict['PASSWORD'], dsn) 
Example #24
Source File: db.py    From nightmare with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, **keywords): 
        import cx_Oracle as db 
        if 'pw' in keywords: 
            keywords['password'] = keywords.pop('pw') 

        #@@ TODO: use db.makedsn if host, port is specified 
        keywords['dsn'] = keywords.pop('db') 
        self.dbname = 'oracle' 
        db.paramstyle = 'numeric' 
        self.paramstyle = db.paramstyle

        # oracle doesn't support pooling 
        keywords.pop('pooling', None) 
        DB.__init__(self, db, keywords) 
Example #25
Source File: basedb.py    From torngas with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, **keywords):
        import cx_Oracle as db

        if 'pw' in keywords:
            keywords['password'] = keywords.pop('pw')

            #@@ TODO: use db.makedsn if host, port is specified
        keywords['dsn'] = keywords.pop('db')
        self.dbname = 'oracle'
        db.paramstyle = 'numeric'
        self.paramstyle = db.paramstyle

        # oracle doesn't support pooling
        keywords.pop('pooling', None)
        DB.__init__(self, db, keywords) 
Example #26
Source File: base.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def _connect_string(self):
        settings_dict = self.settings_dict
        if not settings_dict['HOST'].strip():
            settings_dict['HOST'] = 'localhost'
        if settings_dict['PORT'].strip():
            dsn = Database.makedsn(settings_dict['HOST'],
                                   int(settings_dict['PORT']),
                                   settings_dict['NAME'])
        else:
            dsn = settings_dict['NAME']
        return "%s/%s@%s" % (settings_dict['USER'],
                             settings_dict['PASSWORD'], dsn)