コード例 #1
0
ファイル: test_packet.py プロジェクト: therodfather/geneva
def test_dnsqr():
    """
    Tests DNSQR.
    """
    pkt = UDP() / DNS(ancount=1) / DNSQR()
    pkt.show()
    packet = layers.packet.Packet(pkt)
    packet.show()
    assert len(packet.layers) == 3
    assert "UDP" in packet.layers
    assert "DNS" in packet.layers
    assert "DNSQR" in packet.layers
    pkt = IP() / UDP() / DNS() / DNSQR()
    packet = layers.packet.Packet(pkt)
    assert str(packet)
コード例 #2
0
class UDPLayer(object):
    """docstring for TCPLayer"""
    def __init__(self, arguments={}):
        # super(IPLayer, self).__init__()
        self.packet = None
        if not isinstance(arguments, dict): return "Please provide a dictionay"
        self.arguments = arguments

    def make(self):
        self.packet = UDP()
        for param in self.arguments:
            if not hasattr(self.packet, param): continue
            setattr(self.packet, param, self.arguments[param])
        return self

    def updatePacket(self, arguments={}):
        if not isinstance(arguments, dict): return "Please provide a dictionay"
        for param in arguments:
            if not hasattr(self.packet, param): continue
            setattr(self.packet, param, arguments[param])
        return self

    def getPacket(self):
        return self.packet

    def show(self):
        return self.packet.show()

    def _getUDP(self):
        return UDP()
コード例 #3
0
u = UDP(dport=53)
d = DNS(rd=1,qd=DNSQR(qname=query_input))

# Print all information.
print ""
print "Information"
print "==========="
print "Source IP     : %s" %source_input
print "Destination IP: %s" %destination_input
print "DNS Query     : %s" %query_input
print ""
print "Package details"
print "==============="
print ""
print i.show()
print ""
print u.show()
print ""
print d.show()
print ""

# Confirmation.
is_ok = raw_input("Is it OK? (Y/n)")

# Send or exit.
if is_ok == "y" or is_ok == "Y" or is_ok == "":
    p = send(i/u/d)
else:
    print "Bye."

コード例 #4
0
ファイル: dhcp.py プロジェクト: fmi-retele/dhcp-request
from scapy.sendrecv import sendp, sniff
from scapy.all import DHCP, ARP, BOOTP, Ether, UDP, TCP, IP

# data link layer
ethernet = Ether()
ethernet.show()
ethernet.dst = "ff:ff:ff:ff:ff:ff"

# network layer
ip = IP()
ip.show()
ip.dst = "255.255.255.255"

# transport layer
udp = UDP()
udp.show()
udp.sport = 68
udp.dport = 67

# application layer
bootp = BOOTP()
bootp.show()
bootp.flags = 1

dhcp = DHCP()
dhcp.show()
dhcp.options = [("message-type", "discover"), "end"]

packet = ethernet / ip / udp / bootp / dhcp

sendp(packet)