Incoming ZeroMQ traffic dropped by server due to NAT? - python

I have a ZMQ server listening on port 12345 TCP. When another server connects on that port locally or via VM it works fine, but if I try from a remote server that has to go through port forwarding on my Fios firewall it just bombs. The packets are showing up in Wireshark but ZMQ just ignores them. Is there anyway to get past this?

You shouldn't be able to bind more than once to the same port number, either from the same process or another.
ZMQ should give a failure when you issue bind with a port number already in use. Are you checking return codes?

Related

Why telegram bot doesn't conflict with nginx?

I wrote a simple telegram bot and it works great without conflicting with my firewall. But my question is this, in the firewall I have ports 80 and 443 allowed for my site, but when I write a TCP socket in Python that should work through port 443 or port 80, the OS tells me that I need to run the program from the user's root, but if I start the bot, then the OS does not swear at all about the rights and the bot works quietly. If I still decide to run a socket on port 443 or 80, then the OS replies that these ports are busy.
So, please explain to me why the telegram bot does not conflict with processes and ports?
My server is Ubuntu 22.04
P.S. I already asked this question on stackexchange, but as I understand it, they do not understand telegram bots, I hope you can help me.
Oh... too much misunderstandings in your question. It will be better to understand basics of TCP connection and NAT tables first.
I will try to explain this situation in short
when I write a TCP socket in Python that should work through port 443 or port 80, the OS tells me that I need to run the program from the user's root
80 and 443 are privileged ports and Linux doesn't allow to use it under non-admin users. It has nothing to do with Nginx conflicts and may be solved by proper configuration
If you will try to use non-privileged port like 8080 python may be executed even without admin permissions
So, please explain to me why the telegram bot does not conflict with processes and ports?
Nginx and Python socket are listening at 80 and 443 ports and waiting for incoming connections. You have to access your server IP to initiate connection
Telegram bot (and any another bot) are using Telegram servers to connect. Just imagine that you instantly looking in Telegram app and immediately answering on all messages. Bot doing the same stuff. It is just client for remote server (You don't need to listen 443 at your machine to be able use Telegram app, right?). It is listening no port and don't waiting for incoming connections but waiting for messages at remote server
But you can argue "Hey stop, but Python bot still connected to Telegram servers. What ports it uses? Isn't that is same as the socket?" → Here is the same TCP connection, but Python using OUTGOING dynamic ports to connect Telegram server's INCOMING static port 443. Outgoing port may be 20323 or 27578 for example. It is all about NAT. In short any non-used port may be used to establish connection between remote 443 and local XXXX ports.
You're confusing two things, I think.
nginx/apache/a python server process trying to listen on port 443 or 80 need to be run by root (or another user with elevated privilege levels).
A python bot trying to talk to a telegram server on port 443 doesn't have that limitations; browsers also don't need to run as root.
If this doesn't answer your question you need to be a bit clearer on what you're doing.

Opening public socket with python in Cloud9

I am trying to make a simple and very low level UDP server on Cloud9.
What I would like to do is to open an UDP socket on some port and some ip so that it is accessible from the extern and so that I can get an incoming UDP packet.
I tried to do something like
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", 12345))
But then I wouldn't know the ip. I naively tried to do an ifconfig but I got an ip that I couldn't even ping.
I found out about the IP and PORT environment variables, but IP is always 0.0.0.0.
Is there any way to do what I need?
Sorry to disappoint you, but that is not possible. At this moment only TCP port 8080 in the workspace can be accessed from the internet. So you can develop the UDP server and test its functionality from the same workspace, but to make it work from external sources you should deploy the code to a hosting provider.

ZeroMQ (TCP) workaround for port forwarding

I currently have a ZeroMQ peer to peer network I'm building using Python and PyZMQ. Currently the server listens with a REP TCP socket and connects directly to other peers listening on the same type of socket. This requires port forwarding for clients to get to the servers sadly though. Is there anyway to get around this? Can I do some kind of UDP discovery and then switch over to TCP? Or am I doomed to switch to a UDP style network to solve this problem?

How do I force close a port being used by an independent service?

For example, if I have my minecraft server running on port 25565, I want to have a python script close the port so that all connections will be dropped and no further connections will be made without having to shutdown the service.
I have tried binding a new socket to the same port number and then closing the socket, but it does not have any effect on the server.
I am working in Python 3.3.
Use a firewall for example?
On linux there is the iptables. It's easy to use and powerful.

Making a connection to APNs with bluehost server

I wrote some code to connect to APNs and it works great on my local machine. But when I upload and try to run it on my bluehost server it just takes a long time and then times out. After further testing I can't even get connected to the aps at all. I try
telnet gateway.sandbox.push.apple.com 2195
Connection timed out
I am thinking it has something to do with my bluehost configuration. I have a dedicated IP address and have bluehost claims that port 2195 is open. Any ideas on why I might not be able to make a connection?
After talking with tech support a second time the problem was that port 2195 wasn't open for outgoing connections. They got it opened and I am now in business.

Categories

Resources