netcat

How to display nc return value in Linux shell script?

孤街醉人 提交于 2019-12-10 19:39:32
问题 I am using nc command in my Linux box like below to check if a port is listening; This displays success message: nc -z 192.168.0.2 9000 This displays 0: echo $? I have combined it in a shell script .sh file like below; #!/bin/sh nc -z 192.168.0.2 9000 echo $? This displays 1 instead of expected 0 . Again, if I modify my script like below, it works; #!/bin/sh echo nc -z 192.168.0.2 9000 echo $? But here the problem is, it displays success message on one like, then displays 0 in next line. I

Is there a way to send a continuous stream from a command output to a remote listener

谁都会走 提交于 2019-12-10 17:37:58
问题 I'm using the netcat for unix. when I run python script.py &> logfile.txt , it gets captured continuously. To replicate this remotely, I tried nc -l -p 8011 on the listener (client) and the following for the sender (host or server) : python script.py &> nc 127.0.0.1 8011 python script.py > nc 127.0.0.1 8011 nc 127.0.0.1 8011 < python script.py But nothing seems to work. Please help. 回答1: Is this what you're after? Receiver: nc -l 8011 >logfile.txt Sender: python script.py 2>&1 | nc 127.0.0.1

How to use netcat inside a gitlab-ci.yml

一笑奈何 提交于 2019-12-10 14:17:50
问题 I try to inspect that a service is up inside a gitlab runner. For that I use netcat in my .gitlab-ci.yml image: python:latest before_script: - apt-get update -yq - apt-get install -y python-dev python-pip tree ## check about Rabbit - apt-get install -y curl netcat - nc -v -zw3 rabbitmq 15672 but when I run I get this error:: Unpacking netcat (1.10-41) ... Setting up netcat-traditional (1.10-41) ... update-alternatives: using /bin/nc.traditional to provide /bin/nc (nc) in auto mode Setting up

How to send big chunk of data in one UDP packet?

百般思念 提交于 2019-12-10 11:07:12
问题 trying to send UDP packets using Netcat nc -u 127.0.0.1 1234 And using tcpdump to see actual packets tcpdump -i any -vv -n udp dst port 1234 In theory the UDP packet size can be about 64K, however when I'm sending a message with size bigger than 2048 the Netcat splits the data and sends in 2 separate UDP packets. For example if I send the following long string

Using netcat to send a UDP packet without binding

倖福魔咒の 提交于 2019-12-10 03:47:02
问题 I am trying to use netcat to simulate a NAT traversal protocol. I have one instance that is listening for UDP packets on port 6666, as so: nc -ul 6666 In another terminal window, I am trying to periodically send a UDP packet from port 6666 (to open the return path on my router. this would be in a script that repeats every 20 seconds to re-open the port) nc -u -p6666 mypinghost.com 4444 The problem is netcat fails on this ping call with the message: nc: bind failed: Address already in use

Best way to interact with a service for exploitation purpose

主宰稳场 提交于 2019-12-09 07:45:32
Suppose I have a service to interact with. Using netcat it would be something like this: > nc 127.0.0.1 8080 hello hi how are you? I want to automatize the interaction with this service in order to perform some attack e.g. format string. So I create a Python script and that was really painful to make it work. Here's the code: t = Telnet(HOST, PORT) t.write('2\n') for _ in xrange(10)): print(t.read_some()) t.write('3\n') for _ in xrange(12)): print(t.read_some()) The problem here is the response from the service. The behavior I was expecting from this script was the following: Send request for

run a command conditionally with netcat and grep

时光怂恿深爱的人放手 提交于 2019-12-09 01:21:43
问题 I need netcat to listen on incomming HTTP requests, and depending on the request, I need to run a script. So far I have this; netcat -lk 12345 | grep "Keep-Alive" So every time netcat recieves a package that contains a "keep-alive", I need to fire a script. It needs to run in the crontab... Thanks for your help! 回答1: How about this? #!/bin/bash netcat -lk -p 12345 | while read line do match=$(echo $line | grep -c 'Keep-Alive') if [ $match -eq 1 ]; then echo "Here run whatever you want..." fi

Sockets working in openSUSE do not work in Debian?

試著忘記壹切 提交于 2019-12-08 06:28:10
问题 I have a C/C++ TCP client working in OpenSUSE but not in Debian. I'm using nc -l 4242 for the server. Then I connect with ./my_client 127.0.0.1 4242 on my Debian system (Sid) and it will fail when using the connect function. Can you confirm if you have the same error too, using Debian or maybe another OS? Where does the problem come from? Here's the code: #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netdb.h> #include <unistd.h> #include <stdlib.h> #include

Best way to interact with a service for exploitation purpose

老子叫甜甜 提交于 2019-12-08 03:52:51
问题 Suppose I have a service to interact with. Using netcat it would be something like this: > nc 127.0.0.1 8080 hello hi how are you? I want to automatize the interaction with this service in order to perform some attack e.g. format string. So I create a Python script and that was really painful to make it work. Here's the code: t = Telnet(HOST, PORT) t.write('2\n') for _ in xrange(10)): print(t.read_some()) t.write('3\n') for _ in xrange(12)): print(t.read_some()) The problem here is the

Stream a continuously growing file over tcp/ip

流过昼夜 提交于 2019-12-07 09:48:23
问题 I have a project I'm working on, where a piece of Hardware is producing output that is continuously being written into a textfile. What I need to do is to stream that file as it's being written over a simple tcp/ip connection. I'm currently trying to that through simple netcat, but netcat only sends the part of the file that is written at the time of execution. It doesn't continue to send the rest. Right now I have a server listening to netcat on port 9000 (simply for test-purposes): netcat