Skip to content

lotabout/pscat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Socat in one python file

The initial goal was replace socat in kubctl port-forward (which however is no longer required in newer version), so that in systems that were not able to install socat this script could be a replacement.

What's been done

  • TCP-LISTEN:<port> for creating server
    • only fork and reuseaddr option were implemented
  • TCP:<host>:<port> and TCP4:<host>:<port> for create connections
  • OPEN:<file-path> for opening file for reading
  • - for stdin and stdout, you could use shell's redir for reading from and writing to files
  • No line ending tranlation at all. (I don't need it)

None Goal

  • Implement all the features of socat

Example

./pscat.py <addr1> <addr2>

Think pscat as a tool for creating pipes connecting the read end of addr1 and write end of addr2 and vice versa.

As an echo server

./pscat.py - TCP-LISTEN:8080

Note that TCP-LISTEN will accept only one connection. If you need to keep the server running, add fork option:

./pscat.py - TCP-LISTEN:8080,fork

As an echo client

./pscat.py - TCP:localhost:8080

transfer a file

# server side for receiving (with an IP for connection)
./pscat.py - TCP-LISTEN:8080 > file
# client side for sending
./pscat.py - TCP:server:8080 < file
# server side for sending (with an IP for connection)
./pscat.py - TCP-LISTEN:8080 < file
# client side for receiving
./pscat.py - TCP:server:8080 > file

As a proxy

Listening on port 8080 and transfer all data to remote:port.

./pscat.py TCP-LISTEN:8080 TCP:remote:port

About

socat in one python file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages