示例#1
0
def start_redir(lhost=None, lport=25, cport=9025):
    """start_redir(lhost=None, lport=25, cport=9025)
Starts the redir program in such a way as to ensure that whatever
listening port is specified, local or remote, connections get to the
cport on the host where this is run. If remote execution is necessary
then SSH will be used.  lhost defaults to localhost."""
    from pycopia import socket
    if lhost is None:
        lhost = socket.getfqdn()
    if socket.check_port(lhost, lport):
        raise RuntimeError, "something is already listening on (%r, %r)" % (
            lhost, lport)
    if socket.islocal(lhost):
        if perm_check():
            return redir(lport, cport)
        else:
            raise RuntimeError, "cannot run redir as non-root. check suid bit."
    else:
        myself = socket.getfqdn()
        # for this to work it assumes a lot...
        # 1. ssh is configured for public-key authentication (no
        # password).
        # 2. redir exists and is on the PATH on the remote host.
        # 3. redir is suid-root on the host.
        return remote_redir(lhost, lport, cport, caddr=myself)
示例#2
0
def killall(lhost=None):
    from pycopia import socket
    from pycopia import proctools
    if lhost is None or socket.islocal(lhost):
        proctools.killall("redir")
    else:
        from pycopia import sshlib
        sshlib.ssh_command(lhost, "killall redir")
示例#3
0
def start_redir(lhost=None, lport=25, cport=9025):
    """start_redir(lhost=None, lport=25, cport=9025)
Starts the redir program in such a way as to ensure that whatever
listening port is specified, local or remote, connections get to the
cport on the host where this is run. If remote execution is necessary
then SSH will be used.  lhost defaults to localhost."""
    from pycopia import socket
    if lhost is None:
        lhost = socket.getfqdn()
    if socket.check_port(lhost, lport):
        raise RuntimeError, "something is already listening on (%r, %r)" % (lhost, lport)
    if socket.islocal(lhost):
        if perm_check():
            return redir(lport, cport)
        else:
            raise RuntimeError, "cannot run redir as non-root. check suid bit."
    else:
        myself = socket.getfqdn()
        # for this to work it assumes a lot...
        # 1. ssh is configured for public-key authentication (no
        # password).
        # 2. redir exists and is on the PATH on the remote host.
        # 3. redir is suid-root on the host.
        return remote_redir(lhost, lport, cport, caddr=myself)