Pyhotn's P2P-SIP network phone test

Source: Internet
Author: User

P2p-sip is a peer-to-peer telephone protocol, and someone wrote a python implementation.

This only supports python2,2.6 above

PIP installation, or download installation package decompression.

After decompression has the readme, chews the English.

Write webcaller.py

Import gevent, sys from gevent import monkey; Monkey.patch_all () from GEVENT.PYWSGI import wsgiserver to CGI import Parse_qs, escape import logging from logging Impor

T config logging.config.fileConfig (' logging.conf ') #logger = Logging.getlogger (__name__) logger = Logging.getlogger () From caller import Options from gevent import queue, Timeout freeaccounts = queue. Queue () From app import Sipstackcaller bac, int_ip = none, none maxwait = 5 Import Queue def application (env, start_re Sponse): D = Parse_qs (env[' query_string ']) peers = D.get (' Peer ', [' unknown ']) response_body = ' If env[' remote_a  DDR '].startswith (' 14.29.2. ') or env[' remote_addr '] = = ' 127.0.0.1 ' \ or env[' remote_addr ' '].startswith ' (' 192.168.36. ') or env[' remote_addr '].startswith (' 10.17.41. '): Gevent.spawn (Callpeers, peers) status = ' OK ' Else:stat US = ' 403 Forbidden ' response_headers = [(' Content-type ', ' Text/plain '], (' Content-length ', str (re
 Sponse_body))] Start_response (status, Response_headers) return [response_body] def callpeers (peers): User, domain, password = No NE, none, none try:for peer in Peers:peer = Escape (peer) Peer = ' sip: ' +peer+ ' @gd. ctcims.cn ' Logg  Er.info (' calling ' + Peer) (user, domain, password) = Freeaccounts.get (timeout=maxwait) try:options = Options (user, domain, password, bac=bac, int_ip=int_ip, To=peer, uri=peer) caller = Sipstackcaller.
          Caller (Options) gevent.sleep logger.info (' Hangup call to ' + str (caller.options.to)) Try: Gevent.with_timeout (caller.close) except Timeout:logger.warn (' Caller.close timeout ') ex Cept Exception as E:logger.warn (e) finally:if user and domain and password:logger.info ( ' Freeaccounts.put ') freeaccounts.put ((user, domain, password)) except Queue.Empty:logger.warn (' Get from Q Ueue timeout ') except Exception asE:logger.warn (e) def hangup (caller, account): Try:caller.close () Except:pass Finally:freeaccou Nts.put (account) Logger.info (' Hangup call to ' + str (caller.options.to)) If __name__ = ' __main__ ': TRY:ARGV = s YS.ARGV I, username, password, media, BAC = 1, none, none, none, none int_ip = ' 0.0.0.0 ' jobs, callers = [], [] While I < Len (argv): if argv[i] = = '-U ': If username: (user, domain) = username.split (' @ ') freeaccounts.put ((user, domain, password)) Username, password = none, none username = argv[ I+1] elif argv[i] = = ' P ': password = argv[i+1] elif argv[i] = = ' B ': BAC = argv[i+1] El If argv[i] = = ' I ': int_ip = argv[i+1] i = 2 (user, domain) = username.split (' @ ') freeaccounts.put (
  (user, domain, password))
  Except:logger.exception (' exception ') sys.exit ( -1) print (' Serving on 8088 ... ') Wsgiserver ((', 8088), Application, Log=logger). Serve_forever () 




First you define a constant:

Export Pythonpath=.:external:std:app

Then call Webcaller start:

Python webcaller.py-u +86yourphonenumber@gd.ctcims.cn-p password-b IP

Successful service startup will start 8088 port listening

Call Http://127.0.0.1:8088/?peer=138xxxxxxxx Call

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.