TypeError: NoneType object is not iterable

33 views
Skip to first unread message

SWASTI PARAMITA

unread,
Dec 14, 2021, 10:02:53 AM12/14/21
to sFlow-RT

Greeting,
I have installed sflow-rt to used for my research paper. I'm using Ubuntu 18.04 mininet 2.3.0, python 2.7.17, python3 3.6.9. I have written this function on my script:

collector = '127.0.0.1'
def getIfInfo(ip):
'''

Get interface name of ip address (collector)

'''

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

s.connect((ip, 0))

ip = s.getsockname()[0]

ifconfig = check_output(['ifconfig'])

ifs = re.findall(r'^(\S+).*?inet addr:(\S+).*?', ifconfig, re.S | re.M)

for entry in ifs:

if entry[1] == ip:
return entry

and called it with this line in my script:
(ifname, agent) = getIfInfo(collector)

but it keeps shows me this when I run the script:
    (ifname, agent) = getIfInfo(collector)
'TypeError: NoneType' object is not iterable

Can you please give me an insight about this?
Best regards,

Peter Phaal

unread,
Dec 15, 2021, 12:58:20 PM12/15/21
to sFlow-RT
I am not sure what is going on with your getIfInfo script. The latest extras/sflow.py script takes a different approach:

  def getIfInfo(dst):
    is_64bits = maxsize > 2**32
    struct_size = 40 if is_64bits else 32
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    max_possible = 8 # initial value
    while True:
      bytes = max_possible * struct_size
      names = array('B')
      for i in range(0, bytes):
        names.append(0)
      outbytes = unpack('iL', ioctl(
        s.fileno(),
        0x8912,  # SIOCGIFCONF
        pack('iL', bytes, names.buffer_info()[0])
      ))[0]
      if outbytes == bytes:
        max_possible *= 2
      else:
        break
    s.connect((dst, 0))
    ip = s.getsockname()[0]
    for i in range(0, outbytes, struct_size):
      addr = socket.inet_ntoa(names[i+20:i+24])
      if addr == ip:
        name = names[i:i+16]
        try:
          name = name.tobytes().decode('utf-8')
        except AttributeError:
          name = name.tostring()
        name = name.split('\0', 1)[0]
        return (name,addr)


Reply all
Reply to author
Forward
0 new messages