mac= 00-FF-2E-3B-D1-0B
00-FF-70-6B-82-78 04-EA-56-70-42-9D 04-EA-56-70-42-9E 06-EA-56-70-42-9D 00-D8-61-08-71-E7 00-FF-6A-96-4D-66
How to compare mac addresses In one address to fulfill the condition
import os
for line in os.popen("ipconfig /all"):
if line.lstrip().startswith('Physical Address'):
mac = line.split(':')[1].strip()
print(mac)
user_mac = '00-FF-2E-3B-D1-0B'
if user_mac in mac :
print("work")
else:
print("not work:)")
CodePudding user response:
Just check for a match while you're reading the lines:
import os
user_mac = '00-FF-2E-3B-D1-0B'
found = False
for line in os.popen("ipconfig /all"):
if line.lstrip().startswith('Physical Address'):
mac = line.split(':')[1].strip()
if mac == user_mac:
found = True
break
if found:
print("Found")
else:
print("not found")
CodePudding user response:
If you want to search for a mac or a string try to add an empty list, append all those strings to this list and search for it using a for loop.
import os
list = []
for line in os.popen("ipconfig /all"):
if line.lstrip().startswith('Physical Address'):
mac = line.split(':')[1].strip()
list.append(mac)
mac = "00-FF-2E-3B-D1-0B"
for s in list:
if s == mac:
print("work")
break
print("not work:)")