Listen on a network port and save data to a text file
Netcat is your friend here.
nc -l localhost 10000 > log.txt
Netcat will listen for a connection on port 10000, redirect anything received to log.txt.
Listen on a network port and save data to a text file
Netcat is your friend here.
nc -l localhost 10000 > log.txt
Netcat will listen for a connection on port 10000, redirect anything received to log.txt.
Receiving data from server and writing it into a .txt file using TCP socket programming in python
Open your file in append mode:
with open("Output.txt", "ab") as text_file:
Listening to port and capturing data in python
This sounds like homework... You haven't tried to do it.
In python, to receive and send data (and definitely exchange data), we use the library called socket
. You have two have to scripts, a server-side (which you've written in C) and a client-side script.
# client example
import socket, time
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('localhost', 5000))
while True:
time.sleep(5)
data = client_socket.recv(512)
if data.lower() == 'q':
client_socket.close()
break
print("RECEIVED: %s" % data)
data = input("SEND( TYPE q or Q to Quit):")
client_socket.send(data)
if data.lower() == 'q':
client_socket.close()
break
This is a client-side script example, which receives the data each 5 secs and prints it out. I hope you can adapt it to fit your needs.
Source: Basic Python client socket example
Send String over netcat connection
Try this:
echo -n 'Line of text' | nc <ip> <port>
You can also use temp file syntax:
cat <(echo "Line of test") | nc <ip> <port>
Related Topics
JSON Command Line Formatter Tool for Linux
What Exactly Is Sudo Bang Bang
How to Hide Wget Output in Linux
How to Get "Requests Per Second" for Apache in Linux
How to Start Postgresql Service on Centos 7
Gcc Verbose Mode Output Explanation
Kernel Stack for Linux Process
Flex Development on Linux, What's a Good Free Environment
Why Using Dirname in Find Command Gives Dots for Each Match
Connecting to Amazon Aws Linux Server by Ssh on MAC
How to Pass Argument in Expect Through the Command Line in a Shell Script
What Are My Environment Variables
Rename All Files in Folder to Numbered List 1.Jpg 2.Jpg
How to Check That Two Folders Are the Same in Linux
Linux Command to Check New Files in File System
How to Conveniently Sync a File Between Two Git Repositories