Skip to content

Instantly share code, notes, and snippets.

from scapy.all import *
from scapy.packet import *
import threading
from time import sleep
def getmac(targetip):
arppacket = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(op=1, pdst=targetip)
try:
targetmac = srp(arppacket, timeout=3, verbose=False)[0][0][1].hwsrc
except:
targetmac = ""
@aisayko
aisayko / bulk_upsert.py
Last active May 8, 2022 23:53
Postgresql bulk upsert in Python (Django)
def bulk_upsert(model, fields, values, by):
"""
Return the tuple of (inserted, updated) ids
"""
result = (None, None)
if values:
stmt = """
WITH data_set AS (
INSERT INTO %s (%s)