Python Forum
unexpected output while parsing file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unexpected output while parsing file
#4
Thanks, its working perfectly... I have modified code for MAC OUI and working.

import re

def macvendor(mac_add):
           vendor = p.get_manuf(mac_add)
           return vendor

if __name__ == "__main__":
     dnlist = []
     maclist = []
     with open('bulkdn.txt','r') as f:
          for line in f:
              if line.strip() == '-':
                  dnlist.append(['-'*10])

              if '@ttml' in line:
                  dn = re.findall(r'\d{10}',line)
                  dnlist.append(dn)

              if 'svc:1' in line:
                  mac = re.findall(r'mac:[a-fA-F0-9]{2}[:][a-fA-AF0-9]{2}[:][a-fA-F0-9]{2}[:][a-fA-F0-9]{2}[:][a-fA-F0-9]{2}[:][a-fA-F0-9]{2}',line)
                  maclist.append(mac)

          i=0
          from manuf import manuf
          p = manuf.MacParser(update=True)
          for dn,mac in zip(dnlist,maclist):
               mac = (", ".join(mac)).split('mac:')[1]
               print('{} {} {} {}'.format(i,(", ".join(dn)),mac,macvendor(mac)))
               i+=1
Output:
24128 7120801937 00:26:5a:44:0a:21 D-Link 24129 7120801943 00:17:7c:80:56:83 Smartlin 24130 7120801963 00:17:7c:61:65:aa Smartlin 24131 7120801964 00:17:7c:6c:5a:28 Smartlin 24132 7120801987 08:35:71:ff:2c:3a Caswell 24133 7120801995 00:02:b6:44:f2:b5 Acrosser 24134 7120801996 00:17:7c:70:54:1e Smartlin 24135 7120802002 00:17:7c:75:c6:06 Smartlin 24136 7120802009 00:17:7c:78:8c:18 Smartlin 24137 7120802021 00:17:7c:75:6d:7e Smartlin 24138 7120802027 00:17:7c:80:4b:e3 Smartlin 24139 7120802036 10:62:eb:6a:b3:b6 D-LinkIn 24140 7120802046 00:17:7c:77:af:cf Smartlin 24141 7120802048 00:17:7c:6e:10:25 Smartlin
Reply


Messages In This Thread
unexpected output while parsing file - by anna - Apr-26-2018, 07:22 AM
RE: unexpected output while parsing file - by anna - Apr-27-2018, 08:00 AM
RE: unexpected output while parsing file - by anna - Apr-28-2018, 05:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unexpected EOF while parsing dawid294 1 490 Jan-03-2024, 04:22 PM
Last Post: deanhystad
  Unexpected output Starter 2 584 Nov-22-2023, 12:08 AM
Last Post: Starter
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 849 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Unexpected output while using random.randint with def terickson2367 1 598 Oct-24-2023, 05:56 AM
Last Post: buran
  Unexpected output from df.loc when indexing by label idratherbecoding 6 1,329 Apr-19-2023, 12:11 AM
Last Post: deanhystad
Video doing data treatment on a file import-parsing a variable EmBeck87 15 3,127 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,207 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,820 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Parsing xml file deletes whitespaces. How to avoid it? Paqqno 0 1,094 Apr-01-2022, 10:20 PM
Last Post: Paqqno
  Parsing a syslog file ebolisa 11 4,365 Oct-10-2021, 05:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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