Skip to content

Commit

Permalink
Merge pull request #1413 from gpotter2/fancy-ls
Browse files Browse the repository at this point in the history
New explore() function with prompt_toolkit 2.0 integration
  • Loading branch information
guedou committed Oct 24, 2018
2 parents de24687 + eb5a846 commit e64b261
Show file tree
Hide file tree
Showing 44 changed files with 341 additions and 67 deletions.
2 changes: 2 additions & 0 deletions scapy/asn1packet.py
Expand Up @@ -4,6 +4,8 @@
# This program is published under a GPLv2 license

"""
ASN.1 Packet
Packet holding data in Abstract Syntax Notation (ASN.1).
"""

Expand Down
5 changes: 3 additions & 2 deletions scapy/base_classes.py
Expand Up @@ -229,8 +229,9 @@ def __new__(cls, name, bases, dct):
for f in newcls.fields_desc:
if hasattr(f, "register_owner"):
f.register_owner(newcls)
from scapy import config
config.conf.layers.register(newcls)
if newcls.__name__[0] != "_":
from scapy import config
config.conf.layers.register(newcls)
return newcls

def __getattr__(self, attr):
Expand Down
17 changes: 17 additions & 0 deletions scapy/config.py
Expand Up @@ -168,11 +168,28 @@ def __repr__(self):

class LayersList(list):

def __init__(self):
list.__init__(self)
self.ldict = {}

def __repr__(self):
return "\n".join("%-20s: %s" % (l.__name__, l.name) for l in self)

def register(self, layer):
self.append(layer)
if layer.__module__ not in self.ldict:
self.ldict[layer.__module__] = []
self.ldict[layer.__module__].append(layer)

def layers(self):
layers = self.ldict.keys()
result = []
# This import may feel useless, but it is required for the eval below
import scapy # noqa: F401
for lay in layers:
doc = eval(lay).__doc__
result.append((lay, doc.strip().split("\n")[0] if doc else lay))
return result


class CommandsList(list):
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/bier.py
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = BIER
# scapy.contrib.description = Bit Index Explicit Replication (BIER)
# scapy.contrib.status = loads

from scapy.packet import Packet, bind_layers
Expand Down
2 changes: 2 additions & 0 deletions scapy/contrib/cansocket.py
Expand Up @@ -3,6 +3,8 @@
# Copyright (C) Nils Weiss <nils@we155.de>
# This program is published under a GPLv2 license

# scapy.contrib.description = CANSocket Utils
# scapy.contrib.status = loads

"""
CANSocket.
Expand Down
2 changes: 2 additions & 0 deletions scapy/contrib/cansocket_native.py
Expand Up @@ -3,6 +3,8 @@
# Copyright (C) Nils Weiss <nils@we155.de>
# This program is published under a GPLv2 license

# scapy.contrib.description = Native CANSocket
# scapy.contrib.status = loads

"""
Native CANSocket.
Expand Down
2 changes: 2 additions & 0 deletions scapy/contrib/cansocket_python_can.py
Expand Up @@ -3,6 +3,8 @@
# Copyright (C) Nils Weiss <nils@we155.de>
# This program is published under a GPLv2 license

# scapy.contrib.description = Python-Can CANSocket
# scapy.contrib.status = loads

"""
Python-CAN CANSocket Wrapper.
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/carp.py
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = CARP
# scapy.contrib.description = Common Address Redundancy Protocol (CARP)
# scapy.contrib.status = loads

import struct
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/cdp.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python

# scapy.contrib.description = Cisco Discovery Protocol
# scapy.contrib.description = Cisco Discovery Protocol (CDP)
# scapy.contrib.status = loads

#############################################################################
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/dtp.py
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = DTP
# scapy.contrib.description = Dynamic Trunking Protocol (DTP)
# scapy.contrib.status = loads

"""
Expand Down
14 changes: 8 additions & 6 deletions scapy/contrib/eigrp.py
Expand Up @@ -14,7 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = EIGRP
# flake8: noqa: E501

# scapy.contrib.description = Enhanced Interior Gateway Routing Protocol (EIGRP)
# scapy.contrib.status = loads

"""
Expand All @@ -38,7 +40,7 @@
:Thanks:
- TLV code derived from the CDP implementation of scapy. (Thanks to Nicolas Bareil and Arnaud Ebalard) # noqa: E501
- TLV code derived from the CDP implementation of scapy. (Thanks to Nicolas Bareil and Arnaud Ebalard)
http://trac.secdev.org/scapy/ticket/18
- IOS / EIGRP Version Representation FIX by Dirk Loss
"""
Expand All @@ -63,10 +65,10 @@

class EigrpIPField(StrField, IPField):
"""
This is a special field type for handling ip addresses of destination networks in internal and # noqa: E501
This is a special field type for handling ip addresses of destination networks in internal and
external route updates.
EIGRP removes zeros from the host portion of the ip address if the netmask is 8, 16 or 24 bits. # noqa: E501
EIGRP removes zeros from the host portion of the ip address if the netmask is 8, 16 or 24 bits.
"""

__slots__ = ["length_from"]
Expand Down Expand Up @@ -133,7 +135,7 @@ def randval(self):

class EigrpIP6Field(StrField, IP6Field):
"""
This is a special field type for handling ip addresses of destination networks in internal and # noqa: E501
This is a special field type for handling ip addresses of destination networks in internal and
external route updates.
"""
Expand Down Expand Up @@ -281,7 +283,7 @@ def i2repr(self, pkt, x):

def h2i(self, pkt, x):
"""The field accepts string values like v12.1, v1.1 or integer values.
String values have to start with a "v" folled by a floating point number. # noqa: E501
String values have to start with a "v" folled by a floating point number.
Valid numbers are between 0 and 255.
"""

Expand Down
4 changes: 3 additions & 1 deletion scapy/contrib/geneve.py
Expand Up @@ -14,7 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = GENEVE
# flake8: noqa: E501

# scapy.contrib.description = Generic Network Virtualization Encapsulation (GENEVE)
# scapy.contrib.status = loads

"""
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/gtp.py
Expand Up @@ -8,7 +8,7 @@
##
# This program is published under a GPLv2 license

# scapy.contrib.description = GTP
# scapy.contrib.description = GPRS Tunneling Protocol (GTP)
# scapy.contrib.status = loads

from __future__ import absolute_import
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/gtp_v2.py
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = GTPv2
# scapy.contrib.description = GPRS Tunneling Protocol v2 (GTPv2)
# scapy.contrib.status = loads

import struct
Expand Down
14 changes: 8 additions & 6 deletions scapy/contrib/igmp.py
Expand Up @@ -14,7 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = IGMP/IGMPv2
# flake8: noqa: E501

# scapy.contrib.description = Internet Group Management Protocol v1/v2 (IGMP/IGMPv2)
# scapy.contrib.status = loads

from __future__ import print_function
Expand Down Expand Up @@ -67,7 +69,7 @@ class IGMP(Packet):
IPField("gaddr", "0.0.0.0")]

def post_build(self, p, pay):
"""Called implicitly before a packet is sent to compute and place IGMP checksum. # noqa: E501
"""Called implicitly before a packet is sent to compute and place IGMP checksum.
Parameters:
self The instantiation of an IGMP class
Expand Down Expand Up @@ -95,14 +97,14 @@ def igmpize(self):
The rules are:
General:
1. the Max Response time is meaningful only in Membership Queries and should be zero # noqa: E501
1. the Max Response time is meaningful only in Membership Queries and should be zero
IP:
1. Send General Group Query to 224.0.0.1 (all systems)
2. Send Leave Group to 224.0.0.2 (all routers)
3a.Otherwise send the packet to the group address
3b.Send reports/joins to the group address
4. ttl = 1 (RFC 2236, section 2)
5. send the packet with the router alert IP option (RFC 2236, section 2) # noqa: E501
5. send the packet with the router alert IP option (RFC 2236, section 2)
Ether:
1. Recalculate destination
Expand All @@ -113,8 +115,8 @@ def igmpize(self):
were adjusted.
The function will examine the IGMP message to assure proper format.
Corrections will be attempted if possible. The IP header is then properly # noqa: E501
adjusted to ensure correct formatting and assignment. The Ethernet header # noqa: E501
Corrections will be attempted if possible. The IP header is then properly
adjusted to ensure correct formatting and assignment. The Ethernet header
is then adjusted to the proper IGMP packet format.
"""
gaddr = self.gaddr if hasattr(self, "gaddr") and self.gaddr else "0.0.0.0" # noqa: E501
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/igmpv3.py
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = IGMPv3
# scapy.contrib.description = Internet Group Management Protocol v3 (IGMPv3)
# scapy.contrib.status = loads

from __future__ import print_function
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/ikev2.py
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = IKEv2
# scapy.contrib.description = Internet Key Exchange v2 (IKEv2)
# scapy.contrib.status = loads

import logging
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/isis.py
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = ISIS
# scapy.contrib.description = Intermediate System to Intermediate System (ISIS)
# scapy.contrib.status = loads

"""
Expand Down
8 changes: 8 additions & 0 deletions scapy/contrib/isotp.py
Expand Up @@ -6,6 +6,14 @@
# Copyright (C) Enrico Pozzobon <enricopozzobon@gmail.com>
# This program is published under a GPLv2 license

# scapy.contrib.description = ISO-TP (ISO 15765-2)
# scapy.contrib.status = loads

"""
ISOTPSocket.
"""


import ctypes
from ctypes.util import find_library
import struct
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/lacp.py
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = LACP
# scapy.contrib.description = Link Aggregation Control Protocol (LACP)
# scapy.contrib.status = loads

from scapy.packet import Packet, bind_layers
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/lldp.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
#
# scapy.contrib.description = LLDP
# scapy.contrib.description = Link Layer Discovery Protocol (LLDP)
# scapy.contrib.status = loads

"""
Expand Down
3 changes: 3 additions & 0 deletions scapy/contrib/macsec.py
Expand Up @@ -3,6 +3,9 @@
# Copyright (C) Sabrina Dubroca <sd@queasysnail.net>
# This program is published under a GPLv2 license

# scapy.contrib.description = 802.1AE - IEEE MAC Security standard (MACsec)
# scapy.contrib.status = loads

"""
Classes and functions for MACsec.
"""
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/mpls.py
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = MPLS
# scapy.contrib.description = Multiprotocol Label Switching (MPLS)
# scapy.contrib.status = loads

from scapy.packet import Packet, bind_layers, Padding
Expand Down
2 changes: 2 additions & 0 deletions scapy/contrib/mqtt.py
Expand Up @@ -3,6 +3,8 @@
# Copyright (C) Santiago Hernandez Ramos <shramos@protonmail.com>
# This program is published under GPLv2 license

# scapy.contrib.description = Message Queuing Telemetry Transport (MQTT)
# scapy.contrib.status = loads

from scapy.packet import Packet, bind_layers
from scapy.fields import FieldLenField, BitEnumField, StrLenField, \
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/nsh.py
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = NSH Protocol
# scapy.contrib.description = Network Services Headers (NSH)
# scapy.contrib.status = loads

from scapy.all import bind_layers
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/ospf.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# scapy.contrib.description = OSPF
# scapy.contrib.description = Open Shortest Path First (OSPF)
# scapy.contrib.status = loads

# This file is part of Scapy
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/ppi_cace.py
Expand Up @@ -14,7 +14,7 @@

# author: <jellch@harris.com>

# scapy.contrib.description = PPI CACE
# scapy.contrib.description = Parallel Peripheral Interface CACE (PPI CACE)
# scapy.contrib.status = loads

"""
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/ppi_geotag.py
Expand Up @@ -14,7 +14,7 @@

# author: <jellch@harris.com>

# scapy.contrib.description = PPI GEOLOCATION
# scapy.contrib.description = Parallel Peripheral Interface (PPI) Geolocation
# scapy.contrib.status = loads


Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/ripng.py
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = RIPng
# scapy.contrib.description = Routing Information Protocol next gen (RIPng)
# scapy.contrib.status = loads

from scapy.packet import Packet, bind_layers
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/rsvp.py
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.

# scapy.contrib.description = RSVP
# scapy.contrib.description = Resource Reservation Protocol (RSVP)
# scapy.contrib.status = loads

from scapy.compat import chb
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/spbm.py
Expand Up @@ -17,7 +17,7 @@
# https://en.wikipedia.org/wiki/IEEE_802.1aq
# Modeled after the scapy VXLAN contribution

# scapy.contrib.description = SBPM
# scapy.contrib.description = Shorest Path Bridging Mac-in-mac (SBPM)
# scapy.contrib.status = loads

"""
Expand Down
2 changes: 1 addition & 1 deletion scapy/contrib/tacacs.py
Expand Up @@ -16,7 +16,7 @@

# Based on tacacs+ v6 draft https://tools.ietf.org/html/draft-ietf-opsawg-tacacs-06 # noqa: E501

# scapy.contrib.description = TACACS+ Protocol
# scapy.contrib.description = Terminal Access Controller Access-Control System+
# scapy.contrib.status = loads

import struct
Expand Down

0 comments on commit e64b261

Please sign in to comment.