获取指定Mac地址上线
前言
之所以有了这篇文章,是因为实验室里有了摄像头。害怕打鬼泣的时候被发现,所以就写了这个脚本
正文
思路:
利用scapy模块获取局域网内的存活的Mac和IP地址
当匹配到指定的Mac地址存在的话,那么摄像头可能就启动了
发封邮件给自己邮箱
代码:
from scapy.all import *
from threading import Thread
import re
import smtplib
from email.mime.text import MIMEText
from email.header import Header
xj=open('logo.txt','w')
xj.close()
user=input('Please IP,>"192.168.1/24" -->')
user2=input('Please dst Mac -->')
macs=[]
txs=[]
def logo(lg):
print(lg,file=open('logo.txt','a'))
def scan(host,dstmac):
global dstmacs,dstips
while True:
try:
ang,uag=srp(Ether(dst='FF:FF:FF:FF:FF:FF')/ARP(pdst=host),timeout=2) //发送一个包
for send,rcv in ang:
listMac=rcv.sprintf('Mac:%Ether.src%--IP:%ARP.psrc%') //获取存活Mac对应的IP地址
macs.append(listMac)
logo('Obtain Mac {}'.format(listMac))
except Exception as a:
print('[-] Error {}'.format(a))
for u in macs:
zz = re.findall('Mac:[0-9-a-z-A-Z][0-9-a-z-A-Z]:[0-9-a-z-A-Z][0-9-a-z-A-Z]:[0-9-a-z-A-Z][0-9-a-z-A-Z]:[0-9-a-z-A-Z][0-9-a-z-A-Z]:[0-9-a-z-A-Z][0-9-a-z-A-Z]:[0-9-a-z-A-Z][0-9-a-z-A-Z]|IP:*.*.*',str(u))
cl=str(zz).replace('[','').replace(']','').replace('Mac:','').replace("'",'') //正则过滤
if dstmac in cl:
tx = 0
txs.append(tx)
print('[+] Match to the corresponding Mac address:{}'.format(dstmac))
dstmacs=dstmac
zz2=re.findall('IP:*.*.*',str(cl))
for dstip in zz2:
dp=str(dstip).replace('IP:','').strip()
print('[+] The corresponding IP address is:{}'.format(dp))
logo('[+] The corresponding IP address is:{}'.format(dp))
dstips=dp
else:
logo('[-] No match to the corresponding Mac address.')
for v in txs:
print(v)
if int(v)==0:
print(dstmacs,dstips)
emails(dstmacs,dstips)
break
else:
continue
def emails(dstmacs,dstips): //发送邮箱
try:
username='**********'
password='*******'
messeng=MIMEText('警告:指定的Mac地址上线,老师可能来了。快不要玩游戏,Mac:{},IP:{}'.format(dstmacs,dstips),'plain','utf-8')
messeng['From']=Header('警告信息','utf-8')
messeng['TO']=Header('422926799@qq.com','utf-8')
messeng['Subject']=Header('警告','utf-8')
smtp=smtplib.SMTP()
smtp.connect('smtp.sohu.com','25')
smtp.login(username,password)
smtp.sendmail('chinaanonymous@sohu.com',['422926799@qq.com'],messeng.as_string())
smtp.quit()
print('[+] send email ok')
exit()
except Exception as r:
print(r)
exit()
if __name__ == '__main__':
t=Thread(target=scan,args=(user.strip(),user2.strip()))
t.start()
测试结果:
转载请注明:转自422926799.github.io
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。
文章标题:获取指定Mac地址上线
本文作者:九世
发布时间:2018-10-20, 07:25:09
最后更新:2019-04-19, 20:36:16
原始链接:http://jiushill.github.io/posts/15535e9f.html版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。