在提供的路径中创建.db文件。打印输出显示在终端窗口中,但.db文件中没有数据/模式。没有错误出现,语法看起来是正确的。这是代码。我不知道为什么,conn.commit()
是在正确的领域。任何信息将不胜感激。创建数据库文件,无数据/模式
from scapy.all import *
from scapy.layers import dhcp
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
runtime = logging.getLogger('scapy.runtime')
runtime.setLevel(logging.ERROR)
loading = logging.getLogger('scapy.loading')
loading.setLevel(logging.ERROR)
from scapy.layers.l2 import Ether
from scapy.layers.all import BOOTP
from scapy.layers.all import DHCP, DHCPTypes, DHCPOptions, DHCPRevOptions
from scapy import route
import urllib
import urllib3
from urllib.request import urlopen
import os
import sqlite3
from datetime import datetime
import sys
DIR_NAME = os.path.dirname(__file__)
db_path = os.path.join(DIR_NAME, "/home/dtman/Desktop/Secure_DHCP /secureDHCP-DB.db")
conn = sqlite3.connect(db_path)
c = conn.cursor()
conn.commit()
def make_table():
c.execute('CREATE TABLE IF NOT EXISTS secureDHCP(mac VARCHAR(50), vendorId VARCHAR(50), time VARCHAR(50), oData VARCHAR(50)')
conn.commit()
c.close()
conn.close()
def the_data():
mac = src_mac()
vendorId = vendor()
time = timeData()
oData = optData()
c.execute("INSERT INTO secureDHCP (mac, vendorId, time, oData) VALUES (?, ?, ?, ?)",
(src_mac, vendor, timeDate, optData))
conn.commit()
s=socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0800))
print("Input network interface")
interface = input()
def pkt_data(pkt):
src_mac = pkt.getlayer(Ether).fields['src']
url = 'http://api.macvendors.com/' + src_mac
r = urlopen(url)
vendor = r.read()
timeData = str(datetime.now())
full_options = pkt.getlayer(DHCP).fields['options']
dhcp_options = [o for o in full_options if isinstance(o, tuple)]
for x in dhcp_options:
if x[0] in ('message-type', 'requested_addr', 'hostname'):
optData = x[1]
print('MAC: {} /// Vendor: {} /// Time {} /// optData: {}'.format(src_mac, vendor, timeData, optData))
sniff(iface=interface, prn=pkt_data, filter='udp port (67 or 68)', store=0)
输出端子:
`MAC: 00:00:00:00:00:00 /// Vendor: b'BRAND, Inc.' /// Other Data: 3
MAC: 00:00:00:00:00:00 /// Vendor: b'BRAND, Inc.' /// Other Data: 192.168.1.4
MAC: 00:00:00:00:00:00 /// Vendor: b'BRAND, Inc.' /// Other Data: b'HOSTNAME'`
你可以发布打印输出吗? – DarkCygnus
我的意思是,你可以编辑你的问题,并添加打印的输出...评论吃了不适合的地方代码的编号 – DarkCygnus