Esempio n. 1
0
from datetime import datetime
from datetime import timedelta
import errno
import os
import shutil
import socket
import stat
import sys
import tempfile
import time

import notify
import proto
import state

l = notify.getLogger('tftp')

# UDP datagram size
_UDP_TRANSFER_SIZE = 8192

_PTFTP_DEFAULT_PORT = 69
_PTFTP_DEFAULT_HOST = 'localhost'
_PTFTP_DEFAULT_MODE = 'octet'

_PTFTP_DEFAULT_OPTS = {
    proto.TFTP_OPTION_BLKSIZE: proto.TFTP_LAN_PACKET_SIZE,
}

_PTFTP_RFC1350_OPTS = {
    proto.TFTP_OPTION_BLKSIZE: proto.TFTP_DEFAULT_PACKET_SIZE,
}
Esempio n. 2
0
only responds to DHCP requests that clearly originate from a system
attempting to PXE boot. Use in conjunction with ptftpd.py to have a
full, yet lightweight PXE boot setup.
"""

import errno
import logging
import random
import socket
import struct
import sys
import time

import notify

l = notify.getLogger('dhcpd')

# The IP protocol number in Ethernet frames.
ETHERNET_IP_PROTO = 0x800

# The UDP protocol number in IP datagrams.
IP_UDP_PROTO = 0x11

# The DHCP magic cookie value that precedes option fields.
DHCP_MAGIC_COOKIE = 0x63825363

# DHCP operation types. There are others, but we don't care.
DHCP_OP_DHCPDISCOVER = 1
DHCP_OP_DHCPOFFER = 2
DHCP_OP_DHCPREQUEST = 3
DHCP_OP_DHCPACK = 5
Esempio n. 3
0
import subprocess
import stat
import sys
import threading
import time

import notify
import proto
import state

try:
    import SocketServer as socketserver  # Py2
except ImportError:
    import socketserver  # Py3

l = notify.getLogger('tftpd')

_PTFTPD_SERVER_NAME = 'pFTPd'
_PTFTPD_DEFAULT_PORT = 69
_PTFTPD_DEFAULT_PATH = '/tftpboot'


def get_ip_config_for_iface(iface):
    """Retrieve and return the IP address/netmask of the given interface."""
    if iface not in netifaces.interfaces():
        raise TFTPServerConfigurationError(
                'Unknown network interface {}'.format(iface))

    details = netifaces.ifaddresses(iface)
    inet = details[netifaces.AF_INET][0]
    return inet['addr'], inet['netmask']
Esempio n. 4
0
# (at your option) any later version.
#
# pTFTPd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pTFTPd.  If not, see <http://www.gnu.org/licenses/>.

import re
import struct

import notify

l = notify.getLogger('tftp-proto')
notify.NullEngine.install(l)

# Uncomment these lines to enable full protocol dump.
# import sys
# import logging
#
# notify.StreamEngine.install(l, sys.stderr, logging.DEBUG)

# The following values are defined in the following RFC documents:
#   - RFC1350 - The TFTP Protocol (revision 2)
#   - RFC2347 - TFTP Option Extension
#   - RFC2348 - TFTP Blocksize option
#   - RFC2349 - TFTP Timeout interval and Transfer size options
#   - RFC7440 - TFTP Windowsize Option
Esempio n. 5
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pTFTPd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pTFTPd.  If not, see <http://www.gnu.org/licenses/>.

import re
import struct

import notify
l = notify.getLogger('tftp-proto')
notify.NullEngine.install(l)

# Uncomment these lines to enable full protocol dump.
# import sys
# import logging
#
# notify.StreamEngine.install(l, sys.stderr, logging.DEBUG)

# The following values are defined in the following RFC documents:
#   - RFC1350 - The TFTP Protocol (revision 2)
#   - RFC2347 - TFTP Option Extension
#   - RFC2348 - TFTP Blocksize option
#   - RFC2349 - TFTP Timeout interval and Transfer size options

# TFTP data packet size. A data packet with a length less than this
Esempio n. 6
0
only responds to DHCP requests that clearly originate from a system
attempting to PXE boot. Use in conjunction with ptftpd.py to have a
full, yet lightweight PXE boot setup.
"""

import errno
import logging
import random
import socket
import struct
import sys
import time

import notify

l = notify.getLogger('dhcpd')

# The IP protocol number in Ethernet frames.
ETHERNET_IP_PROTO = 0x800

# The UDP protocol number in IP datagrams.
IP_UDP_PROTO = 0x11

# The DHCP magic cookie value that precedes option fields.
DHCP_MAGIC_COOKIE = 0x63825363

# DHCP operation types. There are others, but we don't care.
DHCP_OP_DHCPDISCOVER = 1
DHCP_OP_DHCPOFFER = 2
DHCP_OP_DHCPREQUEST = 3
DHCP_OP_DHCPACK = 5
Esempio n. 7
0
side, the amount of configuration required to get a PXE boot system
working is laughably small: specify the interface, the directory to
serve over TFTP and the name of the PXE boot file, and you're all set.
"""

import errno
import logging
import socket
import sys
import threading

import notify
import tftpserver
import dhcpserver

l = notify.getLogger('pxed')


class DHCPThread(threading.Thread):
    def __init__(self, iface, bootfile, router):
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.server = dhcpserver.DHCPServer(iface, bootfile, router=router)

    def run(self):
        self.server.serve_forever()


def main():
    import optparse