Python Forum
how to combine mumtiple for loops in single loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to combine mumtiple for loops in single loop
#21
Sorry Wavic, fail to understand this.
Reply
#22
These characters you're trying to print. They have no graphical representation.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#23
its working now...

Easysnmp doesn't honour the textual conventions when MIBs are loaded.


from easysnmp import Session

# Create an SNMP session to be used for all our requests
session = Session(hostname='10.124.xxx.xx', community='xxxwifi', version=2)

# Perform an SNMP walk
system_items = session.walk('1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.1')

for item in system_items:
    print ':'.join('{:02x}'.format(ord(x)) for x in item.value)
Output:
04:4f:aa:34:a2:80 04:4f:aa:34:a7:20 1c:b9:c4:01:cc:50 1c:b9:c4:01:e9:b0 1c:b9:c4:03:79:70 1c:b9:c4:03:7a:a0 1c:b9:c4:03:7b:00
command line output
Output:
SNMPv2-SMI::enterprises.25053.1.3.2.1.1.2.2.1.1.6.4.79.170.52.162.128 = Hex-STRING: 04 4F AA 34 A2 80 SNMPv2-SMI::enterprises.25053.1.3.2.1.1.2.2.1.1.6.4.79.170.52.167.32 = Hex-STRING: 04 4F AA 34 A7 20 SNMPv2-SMI::enterprises.25053.1.3.2.1.1.2.2.1.1.6.28.185.196.1.204.80 = Hex-STRING: 1C B9 C4 01 CC 50 SNMPv2-SMI::enterprises.25053.1.3.2.1.1.2.2.1.1.6.28.185.196.1.233.176 = Hex-STRING: 1C B9 C4 01 E9 B0 SNMPv2-SMI::enterprises.25053.1.3.2.1.1.2.2.1.1.6.28.185.196.3.121.112 = Hex-STRING: 1C B9 C4 03 79 70 SNMPv2-SMI::enterprises.25053.1.3.2.1.1.2.2.1.1.6.28.185.196.3.122.160 = Hex-STRING: 1C B9 C4 03 7A A0 SNMPv2-SMI::enterprises.25053.1.3.2.1.1.2.2.1.1.6.28.185.196.3.123.0 = Hex-STRING: 1C B9 C4 03 7B 00

Help required now, not able to print for multiple oid, something going wrong

 host = '10.124.115.10'

     session = Session(hostname=host, community='ttlwifi', version=2)

     WLCip,SCGAPMac = (list(session.bulkwalk('1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.' + c ,non_repeaters=0, max_repetitions=50)) for c in ('1','10'))

     for i in range(len(WLCip)):
         mac_address = ':'.join('{:02x}'.format(ord(x)) for x in SCGAPMac[i].value)
         #print (SCGAPMac[i].value)
         #print (mac_address)
         print (u'{} {} {}'.format(host,mac_address,WLCip[i].value))
Output:
10.124.115.10 31:30:2e:31:33:38:2e:34:2e:31:36:35 Oª4¢� 10.124.115.10 31:30:2e:31:33:38:2e:34:2e:31:36:34 Oª4§ 10.124.115.10 31:30:2e:31:33:39:2e:32:32:2e:34:36 ¹ÄÌP 10.124.115.10 31:30:2e:31:33:39:2e:32:33:2e:39 ¹Äé° 10.124.115.10 31:30:2e:31:33:38:2e:33:39:2e:32:30 ¹Äyp 10.124.115.10 31:30:2e:31:33:39:2e:32:32:2e:33:38 ¹Äz  10.124.115.10 31:30:2e:31:33:39:2e:37:2e:36 ¹Ä{ 10.124.115.10 31:30:2e:31:33:39:2e:37:2e:37 ¹Ä| 10.124.115.10 31:30:2e:31:33:39:2e:32:32:2e:31:37:38 ¹Ä}� 10.124.115.10 31:30:2e:31:33:39:2e:36:2e:36 ¹Ä}Ð 10.124.115.10 31:30:2e:31:33:39:2e:32:32:2e:33:39 ¹Ä~p 10.124.115.10 31:30:2e:31:33:39:2e:36:2e:38 ¹Ä�À
Reply
#24
Why dont you start with
print (u'{} {} {}'.format(host,mac_address,repr(WLCip[i].value)))
Reply
#25
is this correct?
session = Session(hostname=host, community='ttlwifi', version=2)

     WLCip,SCGAPMac = (list(session.bulkwalk('1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.' + c ,non_repeaters=0, max_repetitions=50)) for c in ('1','10'))
     for i in range(len(WLCip)):
         mac_address = ':'.join('{:02x}'.format(ord(x)) for x in SCGAPMac[i].value)
         #print (u'{} {}'.format(host, (':'.join('{:02x}'.format(ord(x)) for x in SCGAPMac[i].value))))
         print (u'{} {} {}'.format(host,mac_address,repr(WLCip[i].value)))
Output:
10.124.115.10 31:30:2e:31:33:39:2e:32:32:2e:31:30 u'\xf0>\x90\x1f\xe0\x10' 10.124.115.10 31:30:2e:31:33:39:2e:32:32:2e:31:30:39 u'\xf0>\x90\x1f\xe0 ' 10.124.115.10 31:30:2e:31:33:39:2e:38:2e:38:31 u'\xf0>\x90\x1f\xe0\xa0' 10.124.115.10 31:30:2e:31:33:39:2e:36:2e:32:31 u'\xf0>\x90\x1f\xe0\xb0' 10.124.115.10 31:30:2e:31:33:39:2e:36:2e:34:32 u'\xf0>\x90\x1f\xe0\xc0' 10.124.115.10 31:30:2e:31:33:39:2e:38:2e:37:36 u'\xf0>\x90\x1f\xe0\xe0' 10.124.115.10 31:30:2e:31:33:39:2e:38:2e:37:35 u'\xf0>\x90\x1f\xe1\x00' 10.124.115.10 34:39:2e:32:34:38:2e:32:33:2e:31:34:36 u'\xf0>\x90!\xd0@' 10.124.115.10 31:30:2e:31:33:38:2e:33:39:2e:31:39 u'\xf8\xe7\x1e\x1e\xf2 '
Reply
#26
You can do the same for WLCip[i].value as you did for SCGAPMac[i].value.
Reply
#27
this may be crude way, but solving by purpose, is there any other way?
 session = Session(hostname=host, community='xxxwifi', version=2)
     system_items = session.bulkwalk('1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.1')
     mac = []
     for item in system_items:
        mac.append(':'.join('{:02x}'.format(ord(x)) for x in item.value))
     session = Session(hostname=host, community='ttlwifi', version=2)
     SSGMAC,WLCip,SCGAPName,SCGAPNumSta,SCGAPConnStatus = (list(session.bulkwalk('1.3.6.1.4.1.25053.1.3.2.1.1.2.2.1.' + c ,non_repeaters=0, max_repetitions=50)) for c in ('1','10','5','15','16'))
     for i in range(len(WLCip)):
         print ('{} {} {} {} {} {}'.format(host,WLCip[i].value,mac[0],SCGAPName[i].value,SCGAPNumSta[i].value,SCGAPConnStatus[i].value))
Output:
10.124.115.10 10.138.69.54 04:4f:aa:34:a2:80 RuckusAP 6 Connect 10.124.115.10 10.138.69.75 04:4f:aa:34:a2:80 RuckusAP 8 Connect 10.124.115.10 10.138.69.40 04:4f:aa:34:a2:80 RuckusAP 4 Connect 10.124.115.10 10.138.64.173 04:4f:aa:34:a2:80 RuckusAP 12 Connect 10.124.115.10 10.138.64.172 04:4f:aa:34:a2:80 RuckusAP 5 Connect 10.124.115.10 10.138.69.8 04:4f:aa:34:a2:80 RuckusAP 5 Connect 10.124.115.10 10.138.69.55 04:4f:aa:34:a2:80 RuckusAP 2 Connect 10.124.115.10 10.138.69.74 04:4f:aa:34:a2:80 RuckusAP 18 Connect 10.124.115.10 10.138.69.102 04:4f:aa:34:a2:80 RuckusAP 9 Connect

print ('{} {} {} {} {} {}'.format(host,WLCip[i].value,mac[i],SCGAPName[i].value,SCGAPNumSta[i].value,SCGAPConnStatus[i].value))
some changes
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,567 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  Print output in single file using pramika loop deepakkhw 1 2,064 Jul-11-2020, 11:57 AM
Last Post: j.crater
  Unable to combine print statements in for loop adeana 2 1,986 Jun-12-2020, 05:08 PM
Last Post: adeana
  Is it possible to avoid 2 loops inside another loop? SvetlanaofVodianova 2 2,169 Nov-27-2019, 02:30 PM
Last Post: Gribouillis
  Loop through folder of Excel Files and extract single column fioranosnake 2 4,523 Oct-28-2019, 05:19 PM
Last Post: fioranosnake
  Combine two scripts and loop BMC 2 2,039 Feb-17-2019, 02:13 PM
Last Post: BMC
  Loops - new terminal output to file for each loop jm_ice 1 2,582 Dec-21-2018, 02:42 PM
Last Post: ichabod801
  Python-for loop print into single line dragan979 4 7,059 Nov-23-2018, 01:01 AM
Last Post: wavic
  Using nested for loop with a single list mikeavison 3 3,294 Aug-12-2017, 08:13 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020