Skip to content
Snippets Groups Projects
Commit 83c9b88a authored by Phil's avatar Phil
Browse files

Cleaned up some temprary files creation

parent cac1f1a9
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ from scapy.sendrecv import sniff
from scapy.packet import Raw
from scapy.layers.inet import IP,UDP
from scapy.layers.rtp import RTP
from scapy.utils import get_temp_file
def merge(x,y,sample_size=2):
......@@ -29,7 +30,7 @@ def merge(x,y,sample_size=2):
def voip_play(s1,list=None,**kargs):
FIFO="/tmp/conv1.%i.%%i" % os.getpid()
FIFO=get_temp_file()
FIFO1=FIFO % 1
FIFO2=FIFO % 2
......
......@@ -8,7 +8,7 @@ from fields import StrField,ConditionalField,Emph,PacketListField
from config import conf
from base_classes import BasePacket,Gen,SetGen,Packet_metaclass,NewDefaultValues
from volatile import VolatileValue
from utils import import_hexcap,tex_escape,colgen
from utils import import_hexcap,tex_escape,colgen,get_temp_file
from error import Scapy_Exception,log_runtime
try:
......@@ -339,7 +339,7 @@ class Packet(BasePacket):
Creates an EPS file describing a packet. If filename is not provided a temporary file is created and gs is called."""
canvas = self.canvas_dump(**kargs)
if filename is None:
fname = "/tmp/scapy.%i"%os.getpid()
fname = get_temp_file(autoext=".eps")
canvas.writeEPSfile(fname)
os.system("%s '%s.eps' &" % (conf.prog.psreader,fname))
else:
......@@ -350,7 +350,7 @@ Creates an EPS file describing a packet. If filename is not provided a temporary
Creates a PDF file describing a packet. If filename is not provided a temporary file is created and xpdf is called."""
canvas = self.canvas_dump(**kargs)
if filename is None:
fname = "/tmp/scapy.%i"%os.getpid()
fname = get_temp_file(autoext=".pdf")
canvas.writePDFfile(fname)
os.system("%s '%s.pdf' &" % (conf.prog.pdfreader,fname))
else:
......
......@@ -8,7 +8,7 @@ from config import conf
from base_classes import BasePacket,BasePacketList
from packet import Padding
from utils import do_graph,hexdump,make_table,make_lined_table,make_tex_table
from utils import do_graph,hexdump,make_table,make_lined_table,make_tex_table,get_temp_file
import arch
if arch.GNUPLOT:
......@@ -360,7 +360,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
conf.prog.psreader is called"""
d = self._dump_document(**kargs)
if filename is None:
filename = "/tmp/scapy.psd.%i" % os.getpid()
filename = get_temp_file(autoext=".ps")
d.writePSfile(filename)
os.system("%s %s.ps &" % (conf.prog.psreader,filename))
else:
......@@ -373,7 +373,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis
conf.prog.pdfreader is called"""
d = self._dump_document(**kargs)
if filename is None:
filename = "/tmp/scapy.psd.%i" % os.getpid()
filename = get_temp_file(autoext=".pdf")
d.writePDFfile(filename)
os.system("%s %s.pdf &" % (conf.prog.pdfreader,filename))
else:
......
......@@ -9,7 +9,7 @@ from data import *
from arch import *
from config import conf
from packet import Gen
from utils import warning
from utils import warning,get_temp_file
import plist
from error import log_runtime,log_interactive
......@@ -265,7 +265,7 @@ def sendpfast(x, pps=None, mbps=None, realtime=None, loop=0, iface=None):
if loop:
argv.append("--loop=%i" % loop)
f = os.tempnam("scapy")
f = get_temp_file()
argv.append(f)
wrpcap(f, x)
try:
......
......@@ -21,10 +21,10 @@ from base_classes import BasePacketList
## Tools ##
###########
def get_temp_file(keep=False):
def get_temp_file(keep=False, autoext=""):
f = os.tempnam("","scapy")
if not keep:
conf.temp_files.append(f)
conf.temp_files.append(f+autoext)
return f
def sane_color(x):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment