python后台数据库怎么创建_Python后台进程未写入MySQL数据库

如果以前有人问过这个问题,我很抱歉,但是我找不到任何关于这个问题的记录。完全公开:我只使用了几个月的Python和MySQL一个月。在

我在Raspberry Pi(运行RaspbianWheezy)上编写了一个简短的Python脚本,它可以嗅出wifi包并将信号强度信息写入MySQL数据库。我还创建了一个小PHP文件,从数据库中获取信息并将其显示在一个表中(相当基本)。这个小系统的所有组件都按计划工作,但是。。。在

当我在后台运行Python脚本时(sudo Python my_脚本.py&)它似乎没有用新的读数更新MySQL数据库。不过,它也不会抛出错误,并且会毫无问题地输出到控制台(每次截获wifi包并将其RSSI添加到数据库中时,我都会打印一行)。我在启动时使用/etc启动脚本时遇到了相同的问题/rc.本地文件。没有错误,但数据库中也没有更新。在

Python有问题吗?我需要更改的MySQL设置?还有什么我完全没有的吗?在

编辑以添加代码:#!/usr/bin/python

# -*- coding: utf-8 -*-

import MySQLdb as mdb

import sys

from scapy.all import *

# Create connection to MySQL database called 'DATABASE' at localhost with username 'USERNAME' and password 'PASSWORD'

HOST = "localhost"

USER = "USERNAME"

PW = "PASSWORD"

DB = "DATABASE"

con = mdb.connect(HOST, USER, PW, DB)

# set interface that will be used to monitor wifi

interface = "mon0"

with con:

cur = con.cursor()

# This function will be called every time a packet is intercepted. Packet is passed to function as 'p'

def sniffmgmt(p):

# These are the 3 types of management frames that are sent exclusively by clients (allows us to weed out packets sent by APs)

stamgmtstypes = (0, 2, 4)

if p.haslayer(Dot11):

# Make sure packet is a client-only type

if p.subtype in stamgmtstypes:

# Calculate RSSI

sig_str = -(256-(ord(p.notdecoded[-4:-3])))

# Update database with most recent detection

cur.execute("REPLACE INTO attendance(mac_address, rssi, timestamp) VALUES('%s', %d, NOW())" % (p.addr2, sig_str))

# Print MAC address that was detected (debugging only)

print "MAC Address (%s) has been logged" % (p.addr2)

# Tell scapy what interface to use (see above) and which function to call when a packet is intercepted. lfilter limits packets to management frames.

sniff(iface=interface, prn=sniffmgmt, store=0, lfilter=lambda x:x.type==0)

谢谢!

凯尔

请注意:这不是为了恶意使用,而是用于调查我们仓库的产品跟踪技术。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值