How to check port access by Python

from socket import socket, gethostbyname, AF_INET, SOCK_STREAM
import time

'''
Function to check the availability of computer by port.
host - IP-address or computer name
port - port number
count - number of times to repeat the request on port
timeout - amount of seconds between echo requets on port
'''


def is_port(host="127.0.0.1", port=1433, count=1, timeout=1):
checked = False
    for i in range(count):
        ip = gethostbyname(host)
        sock = socket(AF_INET, SOCK_STREAM)
        result = sock.connect_ex((ip, port))
        if result == 0:
            print("*** port is available! ***")
            checked = True
            break
        sock.close()
        time.sleep(timeout)
        if not checked:
            print("*** port is NOT available! ***")
   return checked 
Реклама

How to get all the dependencies Oracle object

1. You want to define all used objects, a change which may affect your object:

select 
    level as hlevel, -- dependencies level
    referenced_owner as ref_owner, -- referenced owner name
    lpad(' ', 2*(level-1)) || referenced_name as ref_name,  -- refernced object name
    referenced_type as ref_type, -- referenced object type
    owner parent_owner, -- parent owner name
    name parent_name, - parent object name
    type parent_type -- parent object type
from dba_dependencies
where referenced_owner not in ('SYS', 'SYSTEM', 'PUBLIC')
start with
    owner = :owner -- owner name of your object
    and name = :object -- your object name
connect by owner = prior referenced_owner
    and name = prior referenced_name
    and type = prior referenced_type
ORDER SIBLINGS BY referenced_name; 

2. You want to define all the objects that are affected by changing of your object:

select 
    level as hlevel, -- dependencies level
    owner as parent_owner, -- parent owner name
    lpad(' ', 2*(level-1)) || name as parent_name, -- parent object name
    type as parent_type, -- parent object type
    referenced_owner, -- referenced owner name
    referenced_name, -- referenced object name
    referenced_type -- referenced object type
from dba_dependencies
where referenced_owner not in ('SYS', 'SYSTEM', 'PUBLIC')
start with
    referenced_owner = :owner -- owner name of your object
    and referenced_name = :object -- your object name
connect by prior owner = referenced_owner
    and prior name = referenced_name
    and prior type = referenced_type
ORDER SIBLINGS BY name
;