当前位置: 首页>>代码示例>>Python>>正文


Python jsonrpclib.Server方法代码示例

本文整理汇总了Python中jsonrpclib.Server方法的典型用法代码示例。如果您正苦于以下问题:Python jsonrpclib.Server方法的具体用法?Python jsonrpclib.Server怎么用?Python jsonrpclib.Server使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jsonrpclib的用法示例。


在下文中一共展示了jsonrpclib.Server方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getEndpoints

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def getEndpoints(switchHostnames, protocol, username, password):
   """ Check that each server is up, and return a mapping from
   hostname to jsonrpclib.Server """
   apiEndpoints = {} # mapping from hostname to the API endpoint
   for switch in switchHostnames:
      url = "{protocol}://{user}:{pw}@{hostname}/command-api".format(
         protocol=protocol, user=username, pw=password, hostname=switch)
      server = jsonrpclib.Server(url)
      try:
         # We should at least be able to 'enable'
         server.runCmds(1, ["enable"])
      except Exception as e:
         print "Unable to run 'enable' on switch", e
         sys.exit(1)
      apiEndpoints[switch] = server
   return apiEndpoints 
开发者ID:PacktPublishing,项目名称:Mastering-Python-Networking-Second-Edition,代码行数:18,代码来源:eapi_2_acl.py

示例2: prepopulateAclFile

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def prepopulateAclFile(filename, aclName, apiEndpoints):
   """ Given a jsonrpclib.Server called 'switch', prepopulate
   'filename' with the ACL contents. If the ACL does not yet exist,
   just print a message """

   # Currently assume all switches have the same config, so just use a
   # random one as the sample.
   apiEndpoint = apiEndpoints.itervalues().next()
   responseList = apiEndpoint.runCmds(1, ["enable",
                                          "show ip access-lists %s" % aclName])
   response = responseList[1] # Only care about the ACL output.
   if not response["aclList"]:
      print "No existing access list named", aclName, "- creating new ACL"
   else:
      # Prepopulate the file with the existing config
      print "Editing existing access list:"
      with open(filename, "w") as f:
         for rule in response["aclList"][0]["sequence"]:
            line = str(rule["sequenceNumber"]) + " " + rule["text"] + "\n"
            print "  ", line,
            f.write(line)
   print 
开发者ID:PacktPublishing,项目名称:Mastering-Python-Networking-Second-Edition,代码行数:24,代码来源:eapi_2_acl.py

示例3: run

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def run():

    # Setup the jsonrpclib for the recon-ng RPC server, stop the API if it cannot connect to the RPC server.
    try:
        client = jsonrpclib.Server('http://localhost:4141')
        sid = client.init()

        # Get the configuration from JSON POST
        content = request.get_json()
        target_module = content['module']
        target_domain = content['domain']
        print(target_domain, target_module)

        # Set the target domain
        client.add('domains', target_domain, sid)
        print(client.show('domains', sid))
        client.use(target_module, sid)

        # Execute the requested module and return the results
        results = client.run(sid)

        return jsonify(results)

    except:
        return traceback.format_exc(), 500 
开发者ID:gradiuscypher,项目名称:bounty_tools,代码行数:27,代码来源:reconng.py

示例4: send_command

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def send_command(cmd, params):
    import jsonrpclib
    server = jsonrpclib.Server('http://%s:%d'%(my_host, my_port))
    try:
        f = getattr(server, cmd)
    except socket.error:
        print "Server not running"
        return 1
        
    try:
        out = f(*params)
    except socket.error:
        print "Server not running"
        return 1

    print json.dumps(out, indent=4)
    return 0 
开发者ID:mazaclub,项目名称:encompass,代码行数:19,代码来源:merchant.py

示例5: blockchain_connect

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def blockchain_connect(self):
    """
    If your Oracle is in test mode, then blockchain server is different than default server
    """
    def server_connection():
      if TEST_MODE:
        self.blockchain_server = jsonrpclib.Server('http://{0}:{1}@{2}:{3}'.format(
            BITCOIND_TEST_RPC_USERNAME,
            BITCOIND_TEST_RPC_PASSWORD,
            BITCOIND_TEST_RPC_HOST,
            BITCOIND_TEST_RPC_PORT))
      else:
        self.blockchain_server = jsonrpclib.Server('http://{0}:{1}@{2}:{3}'.format(
            BITCOIND_RPC_USERNAME,
            BITCOIND_RPC_PASSWORD,
            BITCOIND_RPC_HOST,
            BITCOIND_RPC_PORT))
      socket.setdefaulttimeout(None)
      self.server.help()
    self._connect(server_connection) 
开发者ID:orisi,项目名称:orisi,代码行数:22,代码来源:bitcoinclient.py

示例6: open

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def open(self):
        """
        Opens the connection with the device.
        """
        if self.use_ssl:
            url = 'https://%s:%s@%s/command-api' % (self.username, self.password, self.hostname)
        else:
            url = 'http://%s:%s@%s/command-api' % (self.username, self.password, self.hostname)

        self.device = Server(url) 
开发者ID:spotify,项目名称:pyeos,代码行数:12,代码来源:eos.py

示例7: main

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def main():
    '''
    Use Arista's eAPI to obtain 'show interfaces' from the switch.
    '''

    arista_dict = dict(
        ip='10.10.10.10',
        port=8243,
        username='username',
        password='********'
    )

    eapi_url = 'https://{username}:{password}@{ip}:{port}/command-api'.format(**arista_dict)
    eapi_conn = jsonrpclib.Server(eapi_url)

    interfaces = eapi_conn.runCmds(1, ["show interfaces"])

    # Strip off unneeded data structures
    interfaces = interfaces[0]['interfaces']

    # inOctets/outOctets are fields inside 'interfaceCounters' dict
    data_stats = {}
    for interface, int_values in interfaces.items():
        int_counters = int_values.get('interfaceCounters', {})
        data_stats[interface] = (int_counters.get('inOctets'), int_counters.get('outOctets'))

    # Print output data
    print "\n{:20} {:<20} {:<20}".format("Interface:", "inOctets", "outOctets")
    for intf, octets in data_stats.items():
        print "{:20} {:<20} {:<20}".format(intf, octets[0], octets[1])

    print 
开发者ID:ktbyers,项目名称:pynet,代码行数:34,代码来源:ex1_eapi_interfaces.py

示例8: __init__

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def __init__(self, port_number=8080):
        self.server = jsonrpclib.Server("http://localhost:%d" % port_number) 
开发者ID:ProjetPP,项目名称:PPP-QuestionParsing-Grammatical,代码行数:4,代码来源:demo3.py

示例9: get_daemon

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def get_daemon(config):
    try:
        with open(lockfile(config)) as f:
            host, port = ast.literal_eval(f.read())
    except:
        return
    server = jsonrpclib.Server('http://%s:%d' % (host, port))
    # check if daemon is running
    try:
        server.ping()
        return server
    except:
        pass 
开发者ID:UlordChain,项目名称:Uwallet,代码行数:15,代码来源:daemon.py

示例10: connect

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def connect(self):
    def server_connection():
      self.server = jsonrpclib.Server('http://{0}:{1}@{2}:{3}'.format(
          BITCOIND_RPC_USERNAME,
          BITCOIND_RPC_PASSWORD,
          BITCOIND_RPC_HOST,
          BITCOIND_RPC_PORT))
      socket.setdefaulttimeout(None)
      self.server.help()
    self._connect(server_connection) 
开发者ID:orisi,项目名称:orisi,代码行数:12,代码来源:bitcoinclient.py

示例11: __init__

# 需要导入模块: import jsonrpclib [as 别名]
# 或者: from jsonrpclib import Server [as 别名]
def __init__(self, host, port):
        self.host = host
        self.port = port
        self._server = Server("http://{}:{}".format(self.host, self.port))
        #self.retrieve_function_list() 
开发者ID:CRImier,项目名称:pyLCI,代码行数:7,代码来源:rpc_client.py


注:本文中的jsonrpclib.Server方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。