Linux start listen port

Opening a port for listening

void TcpSocket::ConnectSocket() < socket = new QTcpSocket(this); socket->connectToHost("localhost", 77); if(socket->waitForConnected(3000))< qDebug() write("Hello Server\n\r\n"); socket->waitForBytesWritten(1000); socket->waitForReadyRead(3000); qDebug() bytesAvailable(); qDebug() readAll(); socket->close(); > else < qDebug() > 

Basically, I want to open a tcp socket at localhost:77. I want to write some data to it, get a response, and then output the response. However, right now that port is closed, as most ports are in ubuntu by default. So right now it cannot connect to that port to listen on. Well from what I researched, iptables seems to be the only way to open a port for listening. So I run this line on my machine:

sudo iptables -A INPUT -p tcp --dport 77 -j ACCEPT 
sudo netstat -tulpn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1199/dnsmasq tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1004/cupsd tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1157/postgres tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1121/mysqld tcp6 0 0 ::1:631 . * LISTEN 1004/cupsd udp 0 0 127.0.0.1:53 0.0.0.0:* 1199/dnsmasq udp 0 0 0.0.0.0:68 0.0.0.0:* 1070/dhclient udp 0 0 0.0.0.0:39617 0.0.0.0:* 990/avahi-daemon: r udp 0 0 0.0.0.0:5353 0.0.0.0:* 990/avahi-daemon: r udp6 0 0 . 57021 . * 990/avahi-daemon: r udp6 0 0 . 5353 . * 990/avahi-daemon: r 

netstat doesnt show it to be open. Also I still have the same problem with my program: it cannot connect to 77.

Источник

How to Create Port Listener in Windows or Linux– Handy for Connectivity Test

unix login prompt

Invicti Web Application Security Scanner – the only solution that delivers automatic verification of vulnerabilities with Proof-Based Scanning™.

One of the challenging tasks while working in the project team is to perform the necessary connectivity test though services don’t exist.

This is often you have to do when you are working in a DMZ environment for migration or new projects. Let’s take a real-time example – you are working on migration, and you have to ensure connectivity exists between application “A” to “B” on a particular port.

Well. It’s straightforward you can perform telnet but how about when “B” doesn’t have any service running? That’s where you need the port listener to help in this situation.

If you have a similar situation or feel this would be beneficial for you at work, then here are few ways to achieve this in Windows or UNIX platform.

To create post listener in Windows OS

To have a port listener on a specific port in Windows, you can use the “Port Listener” utility.

This utility is available for free for Windows 95 to Windows 10.

Читайте также:  Изменение яркости экрана linux

port-listener-windows

  • Download Post Listener as zip or exe format from here
  • In this guide, I will download the exe format
  • Double click on downloaded postlistener.exe file
  • It will prompt to select the location to extract the files, click on unzip

port-listener-extract

port-listener-folder

  • Double click on listener to start the utility
  • Enter the port number which you want to test and click on start

port-listener-listening

  • In the above example, I have started listening port on 5500, and it’s time to validate if it’s running.

Open a command prompt and run netstat to validate if port 5500 is listening

netstat-listening-windows

So yes, now I have created a port listener successfully in Windows.

To create post listener in Linux OS

The procedure is slightly different in Linux; here we will use netcat (nc) command to start the listener.

[root@Chandan ~]# netstat -anlp |grep 5500 tcp 0 0 0.0.0.0:5500 0.0.0.0:* LISTEN 21085/nc [root@Chandan ~]#

So here I have port 5500 listened successfully. Doing this in Linux is slightly more comfortable, isn’t it?

To create a port listener using Python

The above two examples are limited to OS. How about having a python script that can work on Windows or UNIX?

Well, I found the below python code which works on Windows and Linux both. Create a file – let’s say portlistener.py with below code

''' Simple socket server using threads ''' import socket import sys HOST = '' # Symbolic name, meaning all available interfaces PORT = 5500 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print 'Socket created' #Bind socket to local host and port try: s.bind((HOST, PORT)) except socket.error as msg: print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] sys.exit() print 'Socket bind complete' #Start listening on socket s.listen(10) print 'Socket now listening' #now keep talking with the client while 1: #wait to accept a connection - blocking call conn, addr = s.accept() print 'Connected with ' + addr[0] + ':' + str(addr[1]) s.close()

Save the file and run it with python command as shown below

[root@Chandan ~]# python portlistener.py Socket created Socket bind complete Socket now listening

Interested in learning Python? Check out this online course.

I hope the above procedure helps you to create a port listener for the connectivity tests.

Источник

How to make port listen in linux

Then run a tool like ftester and you should be able to tell what ports are allowed. Use to forward all ports to the open port by means of the dnat module.

How to listen to all ports (UDP and TCP) or make them all appear open (linux)

Why don’t you run a sniffer on the server and make sure it listens only to traffic coming in from a certain IP or network? Then run a tool like ftester and you should be able to tell what ports are allowed.

A simple and passive solution would be to log all incoming connection attempts to syslog, run your scan, and when you get home look at the logs. With iptables, you can log connections like this:

iptables -A INPUT -p tcp -m state --state new -j LOG --log-prefix "New connection: " 

That way, you don’t need to run a service that answers all connetion attempts.

Читайте также:  Ssh with linux terminal

Use your regular application to list on one port. Use iptables to forward all ports to the open port by means of the dnat module.

iptables -A PREROUTING -i interface -p tcp -j DNAT --to-destination your.ip:port iptables -A PREROUTING -i interface -p tcp -j DNAT --to-destination your.ip:port 

How to set a script to execute when a port receives a, This can also be done with udpsvd which is available on Ubuntu/ Debian (see manpage) as well as built-in to busybox.Example: # simple UDP «echo» on port 9998 udpsvd 0.0.0.0 9998 cat Replace cat with your shell script to execute, stdin is the packet.. With netcat, you can run in a loop to keep listening, and pass each …

How to Check Listening Ports in Linux

This video explains the method to check all the listening ports. Checking the ports which are still listening on the network interface is one of the importan

Listening a particular port on linux to access data comes from mobile device

One of Java’s greatest strengths is that you can pretty much ignore the host operating system as long as you stick to core Java features. In the case you’re describing, you should be able to accomplish everything by simply using the standard Java networking APIs and either the JDBC to access an existing, external database or you could choose any number of embedded Java databases such as Derby. For your stated use case, that you’ll be running the application on Linux is pretty much irrelevant (which should be good news. you don’t need to learn a whole operating system in addition to writing your app ;-).

Here’s a nice client/server tutorial, in that it is broken into steps, and adds each new concept in another step.

Here’s another client/server tutorial with much more detail.

I would write it to accept one connection at a time. Once that works, I would study the new(ish) java.lang.concurrent classes, in particular the ExecutorService, as a way of managing the worker bee handling each connection. Then change your program to handle multiple connections using those classes. Breaking it up in two steps like that will be a lot easier.

Shell script — How to create port listeners in Linux, Below command creates a port listener: nc –l 5500 & as shown below: [root@xyz ~]# netstat -anlp | grep 5500 tcp 0 0 0.0.0.0:5500 0.0.0.0:* LISTEN 2 Stack Exchange Network Stack Exchange network consists of 182 Q&A communities including Stack Overflow , the largest, most trusted online …

How can I change the a port a program listens on?

You have a couple of options:

  1. Use an hex editor to change the value manually. This might be the easiest option, provided you don’t update that binary too often. A method to find the offset to modify would involve disassembling the binary and identify the value to change.
  2. Use a container, like docker, where the binary could still be listening to 32400 inside the container, but you could map this to another port outside of it.
  3. Use LD_PRELOAD, you could use that to intercept calls to bind() and change what is passed to it
Читайте также:  Lsi megaraid sas driver linux

Probably the easiest way to do this, if you don’t have any special tools, is run plex under the control of gdb , with the input of gdb comping from a script. To do that, you need to find the address where 32400 is hardcoded.

objdump -D plex | grep -i 7e90 

should give you something like

40090b: bf 90 7e 00 00 mov $0x7e90,%edi 

Start gdb, set a breakpoint there, run the program until it hits the breakpoint.

gdb plex break *0x40090b run 

Step one instruction, change the register value, and continue running the program:

stepi >> 0x0000000000400910 in main () > rdi 0x7e90 32400 set $rdi=0x7e91 > rdi 0x7e91 32401 cont 

In a different window, check if plex really listens on the other port:

netstat -ntap | grep plex tcp 0 0 0.0.0.0:32401 0.0.0.0:* LISTEN 22018/plex 

Now automate this in a script:

and run that script instead of plex everytime you want to start it on a different port.

Of course, you could also use a hex editor to change the value in the binary directly. You’ll even have to do this if the routine that sets up the listening port gets called repeatedly (so you can’t predict which exact input gdb needs). However, in many cases, this might be the easiest method, since it doesn’t require changing the binary or programming a LD_PRELOAD handler, and changing the port number later is super-easy.

C — On linux, how to check if port is in listen state without, As per your query it seems to be that you want to check open port on your server, but on sure which command need to be run. No need to worries for example we try to found out if port 80 open on your server. First login into server as root user. root@ [~]# whoami root. Now run following command. Usage example`netstat -anp`Feedback

Listen to a conversation using port forwarding

Initially, a see two small possible problems:

  • In Linux B: you should also have an ACCEPT policy in FORDWARD chain.
  • In Linux C: you should invert aplay and nc order on listening command line: nc -l -u 3333 | aplay

Opening a TCP port in Linux — Unix & Linux Stack Exchange, Opening a TCP port in Linux. I am trying to establish a TCP socket between my linux server and my client running on my laptop. The TCP server code I am running is, from socket import * HOST = » PORT = 1999 serversocket = socket (AF_INET,SOCK_STREAM) serversocket.bind ( (HOST,PORT)) serversocket.listen …

Источник

Оцените статью
Adblock
detector