def __init__(self, fichero): parser = make_parser() cHandler = XMLHandler() parser.setContentHandler(cHandler) try: parser.parse(open(fichero)) except FileNotFoundError: print("---->Fichero no encontrado") self.diccionario = cHandler.get_tags()
def __init__(self, fichero): parser = make_parser() cHandler = XMLHandler() parser.setContentHandler(cHandler) try: parser.parse(open(fichero)) except FileNotFoundError: print("->Fichero xml no encontrado") self.diccionario = cHandler.get_tags()
import socket import os import time if __name__ == "__main__": """ Programa principal """ try: CONFIG = sys.argv[1] METHOD = sys.argv[2].upper() OPTION = sys.argv[3] except IndexError: sys.exit("Usage: python uaclient.py config method option") parser = make_parser() cHandler = XMLHandler() parser.setContentHandler(cHandler) parser.parse(open(CONFIG)) UA = cHandler.get_tags() # Creamos el socket, lo configuramos y lo atamos a un servidor/puerto my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) my_socket.connect((UA['regproxy_ip'], int(UA['regproxy_puerto']))) TO = UA['regproxy_ip'] + ':' + UA['regproxy_puerto'] # Enviamos diferentes cosas según el método if METHOD == "REGISTER": try: OPTION = int(OPTION) except ValueError: sys.exit("Usage: int OPTION Required") LINE = UA['account_username'] + ":" + UA['uaserver_puerto']
sys.exit("Usage: python uaclient.py config method option") try: CONFIG = sys.argv[1] METHOD1 = sys.argv[2] METHOD = METHOD1.upper() OPTION = sys.argv[3] except: sys.exit("Usage: python uaclient.py config method option") try: if os.path.exists(CONFIG) is False: sys.exit("This name of file doesn´t exist") # Sacamos los datos del xml parser = make_parser() cHandler = XMLHandler() parser.setContentHandler(cHandler) parser.parse(open(CONFIG)) lista = cHandler.get_tags() # Meto los valores del xml en variables USER_NAME = lista[0]['account']['username'] PASSWD = lista[0]['account']['passwd'] UASERVER_IP = lista[1]['uaserver']['ip'] UASERVER_PORT = lista[1]['uaserver']['puerto'] PORT_AUDIO = lista[2]['rtpaudio']['puerto'] IP_PROXY = lista[3]['regproxy']['ip'] PORT_PROXY = lista[3]['regproxy']['puerto'] PATH_LOG = lista[4]['log']['path'] PATH_AUDIO = lista[5]['audio']['path']
Programa cliente que abre un socket a un servidor """ if __name__ == "__main__": try: FICH = sys.argv[1] if not os.access(sys.argv[1], os.F_OK): print "Usage: the file doesn't exist" sys.exit() except ValueError: print "Usage: python uaclient.py config" parser = make_parser() Handler = XMLHandler() parser.setContentHandler(Handler) parser.parse(open(FICH)) dic_labels = Handler.get_labels() IP_PROXY = dic_labels["regproxy_ip"] PORT_PROXY = int(dic_labels["regproxy_puerto"]) NAME = dic_labels["account_username"] IP = dic_labels["uaserver_ip"] PORT = int(dic_labels["uaserver_puerto"]) AUDIO_PORT = dic_labels["rtpaudio_puerto"] dt = datetime.now().strftime("%Y%m%d%H%M%S") my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) my_socket.connect((IP_PROXY, PORT_PROXY)) try:
import os import hashlib # Comprobamos que se introducen datos correctos if len(sys.argv) != 4: sys.exit("Usage: python uaclient.py config method option") try: CONFIG = sys.argv[1] METOD = sys.argv[2].upper() OPTION = sys.argv[3] except Exception: sys.exit("Usage: python uaclient.py config method option") # lectura de fichero xml parser = make_parser() cHandler = XMLHandler() parser.setContentHandler(cHandler) parser.parse(open(CONFIG)) UA = cHandler.get_tags() # Creamos el socket, lo configuramos y lo atamos a un servidor/puerto my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) my_socket.connect((UA["regproxy_ip"], int(UA["regproxy_puerto"]))) PROXY = UA["regproxy_ip"] + ":" + UA["regproxy_puerto"] # Mandamos información en función del método if METOD == "REGISTER": try: OPTION = int(OPTION) except ValueError: sys.exit("Usage: int OPTION Required") if OPTION > 0:
METODO = sys.argv[2].upper() if METODO == 'REGISTER': OPTION = int(sys.argv[3]) elif METODO == 'INVITE' or 'BYE': OPTION = str(sys.argv[3]) if len(sys.argv) > 4 or len(sys.argv) < 3: print 'Usage: python uaclient.py config method option' raise SystemExit except ValueError: sys.exit('Usage: python uaclient.py config method option') except IndexError: sys.exit('Usage: python uaclient.py config method option') # PARSEAR parser = make_parser() small = XMLHandler() parser.setContentHandler(small) try: parser.parse(open(FICH)) except IOError: sys.exit('Usage: python uaclient.py config method option') dicc = small.get_tags() # Creamos log log_fich = dicc['log_path'] log = LogClass(log_fich) # Creamos socket my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
""" if __name__ == "__main__": try: FichConfig = sys.argv[1] # Fichero XML if not os.access(FichConfig, os.F_OK): # Devuelve True si está el fich sys.exit('Usage: python uaclient.py config method option') METHOD = sys.argv[2].upper() OPTION = sys.argv[3] except IndexError: sys.exit('Usage: python uaclient.py config method option') except ValueError: sys.exit('Usage: python uaclient.py config method option') parser = make_parser() Handler = XMLHandler() parser.setContentHandler(Handler) parser.parse(open(FichConfig)) Dicc = Handler.get_tags() # Diccionario con los atributos del fichero xml NAME = Dicc['account_username'] UAS_IP = Dicc['uaserver_ip'] UA_PORT = Dicc['uaserver_puerto'] RTP_PORT = Dicc['rtpaudio_puerto'] PR_IP = Dicc['regproxy_ip'] PR_PORT = Dicc['regproxy_puerto'] LOG = Dicc['log_path'] SONG = Dicc['audio_path'] PSSWRD = Dicc['account_passwd'] # Contenido que vamos a enviar
def checknonce(nonce): fun_check = hashlib.md5() fun_check.update(bytes(nonce, 'utf-8')) fun_check.update(bytes(passwd, 'utf-8')) fun_check.digest() return fun_check.hexdigest() if __name__ == "__main__": try: METHOD = str.upper(sys.argv[2]) CONFIG = sys.argv[1] OPTION = sys.argv[3] parser = make_parser() Handler = XMLHandler() parser.setContentHandler(Handler) parser.parse(open(CONFIG)) configtags = Handler.get_tags() except IndexError: sys.exit('Usage: ' + 'python3 uaclient.py config method option') except FileNotFoundError: sys.exit('File not found') username = configtags[0][1]['username'] passwd = configtags[0][1]['passwd'] uaserv_ip = configtags[1][1]['ip'] if uaserv_ip == '': uaserv_ip = "127.0.0.1" uaserv_port = str(configtags[1][1]['puerto']) audio_port = (configtags[2][1]['puerto'])
""" Programa cliente que abre un socket a un servidor """ if __name__ == "__main__": try: FICH = sys.argv[1] if not os.access(sys.argv[1], os.F_OK): print "Usage: the file doesn't exist" sys.exit() except ValueError: print "Usage: python uaclient.py config" parser = make_parser() Handler = XMLHandler() parser.setContentHandler(Handler) parser.parse(open(FICH)) dic_labels = Handler.get_labels() IP_PROXY = dic_labels["regproxy_ip"] PORT_PROXY = int(dic_labels["regproxy_puerto"]) NAME = dic_labels["account_username"] IP = dic_labels["uaserver_ip"] PORT = int(dic_labels["uaserver_puerto"]) AUDIO_PORT = dic_labels["rtpaudio_puerto"] dt = datetime.now().strftime("%Y%m%d%H%M%S") my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) my_socket.connect((IP_PROXY, PORT_PROXY)) try: