run

pync.run(args, stdin=None, stdout=None, stderr=None, input=None, capture_output=False, Netcat=<class 'pync.netcat.Netcat'>)[source]

Create and run a Netcat instance. This is similar to running pync from the command-line.

Parameters:
  • args (str) – A string containing command-line arguments.

  • stdin (file, optional) – A file-like object to read outgoing network data from.

  • stdout (file, optional) – A file-like object to write incoming network data to.

  • stderr (file, optional) – A file-like object to write error/verbose/debug messages to.

  • input (bytes, optional) – A byte string to use instead of stdin.

  • capture_output (bool, optional) – If set to True, capture output and return it as a file-like object via the pync.CompletedNetcat.stdout attribute. Defaults to “False”.

  • Netcat (pync.Netcat) – The class to use for the Netcat instance.

Returns:

A CompletedNetcat instance.

Return type:

pync.CompletedNetcat

Examples:

Create a local TCP server on port 8000.
import pync
pync.run('-l localhost 8000')
Connect to a local TCP server on port 8000.
import pync
pync.run('localhost 8000')
Create a local TCP server to host a file on port 8000.
import pync
with open('file.in', 'rb') as f:
    pync.run('-l localhost 8000', stdin=f)
Connect to a local TCP server to download a file on port 8000.
import pync
with open('file.out', 'wb') as f:
    pync.run('localhost 8000', stdout=f)
Create a local TCP server and send a byte string on port 8000.
import pync
pync.run('-l localhost 8000', input=b'Hello, World!')
Connect to a local TCP server and capture output to a byte string.
import pync
result = pync.run('localhost 8000', capture_output=True)
print(result.stdout.decode())
Run pync and return the exit code.
import sys
import pync

result = pync.run(...)
sys.exit(result.returncode)