def send(self, msg):
"""
Sends the IMC message to the node, filling in the destination
:param msg: The IMC message to send
:return:
"""
imcudp_services = self.services['imc+udp']
if not imcudp_services:
logger.error('{} does not expose an imc+udp service'.format(self))
return
# Determine which service to send to based on ip/netmask
# Note: this might not account for funky ip routing
networks = [ip.ip_interface(x[1] + '/' + x[2]).network for x in get_interfaces()]
for svc in imcudp_services:
svc_ip = ip.ip_address(svc.ip)
if any([svc_ip in network for network in networks]):
with IMCSenderUDP(svc.ip) as s:
s.send(message=msg, port=svc.port)
return
# If this point is reached no local interfaces has the target system in its netmask
# Could be running on same system with no available interfaces
# Send on loopback
ports = [svc.port for svc in imcudp_services]
with IMCSenderUDP('127.0.0.1') as s:
for port in ports:
s.send(message=msg, port=port)
评论列表
文章目录