本文整理匯總了Python中pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher.sendMessage方法的典型用法代碼示例。如果您正苦於以下問題:Python AsyncoreDispatcher.sendMessage方法的具體用法?Python AsyncoreDispatcher.sendMessage怎麽用?Python AsyncoreDispatcher.sendMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher
的用法示例。
在下文中一共展示了AsyncoreDispatcher.sendMessage方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
def __init__(self, data, timeout_func=None, receive_func=None, error_func=None):
self.__dict__.update(data)
self.timeout_func = timeout_func
self.receive_func = receive_func
self.error_func = error_func
self.pMod = pMod = api.protoModules[api.protoVersion2c]
self.reqPDU = reqPDU = pMod.SetRequestPDU()
pMod.apiPDU.setDefaults(reqPDU)
pMod.apiPDU.setVarBinds(reqPDU,
map(lambda a: (a[0], pMod.OctetString(str(a[2]))) if a[1] == 'str'
else (a[0], pMod.Integer(int(a[2]))), self.oid_keys_enc_val))
reqMsg = pMod.Message()
pMod.apiMessage.setDefaults(reqMsg)
pMod.apiMessage.setCommunity(reqMsg, self.community)
pMod.apiMessage.setPDU(reqMsg, reqPDU)
self.startedAt = time()
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
# UDP/IPv4
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openClientMode())
transportDispatcher.sendMessage(encoder.encode(reqMsg), udp.domainName, (self.network_address, self.port))
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例2: __init__
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
def __init__(self, data, timeout_func=None, receive_func=None, error_func=None):
self.__dict__.update(data)
self.timeout_func = timeout_func
self.receive_func = receive_func
self.error_func = error_func
headVars = [v2c.ObjectIdentifier(oid) for oid in
map(lambda oid: (int(i) for i in oid.split('.')), self.oid_keys)]
self.reqPDU = reqPDU = v2c.GetBulkRequestPDU()
v2c.apiBulkPDU.setDefaults(reqPDU)
v2c.apiBulkPDU.setNonRepeaters(reqPDU, self.non_repeaters)
v2c.apiBulkPDU.setMaxRepetitions(reqPDU, self.max_repetitions)
v2c.apiBulkPDU.setVarBinds(reqPDU, [(x, v2c.null) for x in headVars])
reqMsg = v2c.Message()
v2c.apiMessage.setDefaults(reqMsg)
v2c.apiMessage.setCommunity(reqMsg, self.community)
v2c.apiMessage.setPDU(reqMsg, reqPDU)
self.startedAt = time()
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openClientMode())
transportDispatcher.sendMessage(encoder.encode(reqMsg), udp.domainName, (self.network_address, self.port))
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例3: __init__
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
def __init__(self, data, timeout_func=None, receive_func=None, error_func=None):
self.__dict__.update(data)
self.timeout_func = timeout_func
self.receive_func = receive_func
self.error_func = error_func
self.pMod = pMod = api.protoModules[api.protoVersion2c]
self.reqPDU = reqPDU = pMod.GetRequestPDU()
pMod.apiPDU.setDefaults(reqPDU)
pMod.apiPDU.setVarBinds(reqPDU, ((oid, pMod.Null('')) for oid in self.oid_keys))
reqMsg = pMod.Message()
pMod.apiMessage.setDefaults(reqMsg)
pMod.apiMessage.setCommunity(reqMsg, self.community)
pMod.apiMessage.setPDU(reqMsg, reqPDU)
self.startedAt = time()
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(self.cbRecvFun)
transportDispatcher.registerTimerCbFun(self.cbTimerFun)
# UDP/IPv4
transportDispatcher.registerTransport(udp.domainName, udp.UdpSocketTransport().openClientMode())
transportDispatcher.sendMessage(encoder.encode(reqMsg), udp.domainName, (self.network_address, self.port))
transportDispatcher.jobStarted(1)
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例4: sendmsg
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
transportDispatcher.registerRecvCbFun(cbRecvFun)
transportDispatcher.registerTimerCbFun(cbTimerFun)
# Initialize UDP/IPv4 transport
udpSocketTransport = udp.UdpSocketTransport().openClientMode()
# Use sendmsg()/recvmsg() for socket communication (required for
# IP source spoofing functionality)
udpSocketTransport.enablePktInfo()
# Enable IP source spoofing (requires root privileges)
udpSocketTransport.enableTransparent()
transportDispatcher.registerTransport(udp.domainName, udpSocketTransport)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, transportAddress
)
# We might never receive any response as we sent request with fake source IP
transportDispatcher.jobStarted(1)
# Dispatcher will finish as all jobs counter reaches zero
try:
transportDispatcher.runDispatcher()
except StopWaiting:
transportDispatcher.closeDispatcher()
else:
raise
示例5: time
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
v2c.apiBulkPDU.setVarBinds(
reqPDU, [ (x, v2c.null) for x,y in varBindTable[-1] ]
)
v2c.apiBulkPDU.setRequestID(reqPDU, v2c.getNextRequestID())
transportDispatcher.sendMessage(
encoder.encode(reqMsg), transportDomain, transportAddress
)
global startedAt
if time() - startedAt > 3:
raise Exception('Request timed out')
startedAt = time()
return wholeMsg
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(cbRecvFun)
transportDispatcher.registerTimerCbFun(cbTimerFun)
transportDispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openClientMode()
)
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, ('demo.snmplabs.com', 161)
)
transportDispatcher.jobStarted(1)
# Dispatcher will finish as job#1 counter reaches zero
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例6: print
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
else:
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
transportDispatcher.jobFinished(1)
return wholeMsg
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(cbRecvFun)
transportDispatcher.registerTimerCbFun(cbTimerFun)
# UDP/IPv4
transportDispatcher.registerTransport(
udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode()
)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.DOMAIN_NAME, ('demo.snmplabs.com', 161)
)
transportDispatcher.jobStarted(1)
# Dispatcher will finish as job#1 counter reaches zero
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例7: AsyncoreDispatcher
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
# Build message
trapMsg = pMod.Message()
pMod.apiMessage.setDefaults(trapMsg)
pMod.apiMessage.setCommunity(trapMsg, 'public')
pMod.apiMessage.setPDU(trapMsg, trapPDU)
transportDispatcher = AsyncoreDispatcher()
# UDP/IPv4
transportDispatcher.registerTransport(
udp.DOMAIN_NAME, udp.UdpSocketTransport().openClientMode()
)
transportDispatcher.sendMessage(
encoder.encode(trapMsg), udp.DOMAIN_NAME, ('demo.snmplabs.com', 162)
)
# UDP/IPv6
transportDispatcher.registerTransport(
udp6.DOMAIN_NAME, udp6.Udp6SocketTransport().openClientMode()
)
transportDispatcher.sendMessage(
encoder.encode(trapMsg), udp6.DOMAIN_NAME, ('::1', 162)
)
# Dispatcher will finish as all scheduled messages are sent
transportDispatcher.runDispatcher()
transportDispatcher.closeDispatcher()
示例8: AsyncoreDispatcher
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
pMod.apiTrapPDU.setGenericTrap(trapPDU, 'coldStart')
# Build message
trapMsg = pMod.Message()
pMod.apiMessage.setDefaults(trapMsg)
pMod.apiMessage.setCommunity(trapMsg, 'public')
pMod.apiMessage.setPDU(trapMsg, trapPDU)
transportDispatcher = AsyncoreDispatcher()
# UDP/IPv4
transportDispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openClientMode()
)
transportDispatcher.sendMessage(
encoder.encode(trapMsg), udp.domainName, ('demo.snmplabs.com', 162)
)
# UDP/IPv6
transportDispatcher.registerTransport(
udp6.domainName, udp6.Udp6SocketTransport().openClientMode()
)
transportDispatcher.sendMessage(
encoder.encode(trapMsg), udp6.domainName, ('::1', 162)
)
## Local domain socket
# transportDispatcher.registerTransport(
# unix.domainName, unix.UnixSocketTransport().openClientMode()
# )
# transportDispatcher.sendMessage(
示例9: AsyncoreDispatcher
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
transportDispatcher.jobFinished(1)
return wholeMsg
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(cbRecvFun)
transportDispatcher.registerTimerCbFun(cbTimerFun)
# UDP/IPv4
transportDispatcher.registerTransport(
udp.domainName, udp.UdpSocketTransport().openClientMode()
)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, ('localhost', 1161)
)
transportDispatcher.jobStarted(1)
## UDP/IPv6 (second copy of the same PDU will be sent)
transportDispatcher.registerTransport(
udp6.domainName, udp6.Udp6SocketTransport().openClientMode()
)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp6.domainName, ('::1', 1161)
)
transportDispatcher.jobStarted(1)
## Local domain socket
開發者ID:stephenoken,項目名稱:-SNMP-Management-Station-for-Wireless-Indoor-Network,代碼行數:33,代碼來源:snmp_fetch.py
示例10: sendmsg
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
transportDispatcher.registerRecvCbFun(cbRecvFun)
transportDispatcher.registerTimerCbFun(cbTimerFun)
# Initialize UDP/IPv4 transport
udpSocketTransport = udp.UdpSocketTransport().openClientMode()
# Use sendmsg()/recvmsg() for socket communication (required for
# IP source spoofing functionality)
udpSocketTransport.enablePktInfo()
# Enable IP source spoofing (requires root privileges)
udpSocketTransport.enableTransparent()
transportDispatcher.registerTransport(udp.DOMAIN_NAME, udpSocketTransport)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.DOMAIN_NAME, transportAddress
)
# We might never receive any response as we sent request with fake source IP
transportDispatcher.jobStarted(1)
# Dispatcher will finish as all jobs counter reaches zero
try:
transportDispatcher.runDispatcher()
finally:
transportDispatcher.closeDispatcher()
示例11: print
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
transportDispatcher.jobFinished(1)
return wholeMsg
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(cbRecvFun)
transportDispatcher.registerTimerCbFun(cbTimerFun)
# UDP/IPv4
udpSocketTransport = udp.UdpSocketTransport().openClientMode().enableBroadcast()
transportDispatcher.registerTransport(udp.DOMAIN_NAME, udpSocketTransport)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.DOMAIN_NAME, ('255.255.255.255', 161)
)
# wait for a maximum of 10 responses or time out
transportDispatcher.jobStarted(1, maxNumberResponses)
# Dispatcher will finish as all jobs counter reaches zero
try:
transportDispatcher.runDispatcher()
finally:
transportDispatcher.closeDispatcher()
示例12: print
# 需要導入模塊: from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher [as 別名]
# 或者: from pysnmp.carrier.asyncore.dispatch.AsyncoreDispatcher import sendMessage [as 別名]
else:
for oid, val in pMod.apiPDU.getVarBinds(rspPDU):
print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
transportDispatcher.jobFinished(1)
return wholeMsg
transportDispatcher = AsyncoreDispatcher()
transportDispatcher.registerRecvCbFun(cbRecvFun)
transportDispatcher.registerTimerCbFun(cbTimerFun)
# UDP/IPv4
udpSocketTransport = udp.UdpSocketTransport().openClientMode().enableBroadcast()
transportDispatcher.registerTransport(udp.domainName, udpSocketTransport)
# Pass message to dispatcher
transportDispatcher.sendMessage(
encoder.encode(reqMsg), udp.domainName, ('255.255.255.255', 161)
)
# wait for a maximum of 10 responses or time out
transportDispatcher.jobStarted(1, maxNumberResponses)
# Dispatcher will finish as all jobs counter reaches zero
try:
transportDispatcher.runDispatcher()
except StopWaiting:
transportDispatcher.closeDispatcher()
else:
raise