I got a server with several of IP's at. Those IP's I want to create sockets through and afterwards from a client, and afterwards send a socket to a webpage.
The problem is that I want to use the IP that the client is calling to create the socket to the webpage, and not just the main IP of the server.

Etc, I connect from client to:
and then I create a socket to a webserver using,
s.bind((gethostname(), 1700))
but that binding will attach it to the main IP: xx.xx.xx.12 and not xx.xx.xx.45 which is the IP I wans to bind to the webserver socket.

Is there any solution of how I can recall the IP that I created the socket through so I not just get the main IP of the server?

gethostbyname / gethostbyaddress will always provide the main ip. That is if the sever is a shared hosting type.

Why not simply provide the ip address you want to bind to?

I have like 150+ different IP's I want to use and create sockets through. If I have to provide it everytime there will be a lot of hardcoding.
Would do it much easier if there is a way to recall the IP that the server was called at.

why hard coding?
you can loop through your ips without any issue.;)

How can the python script then know if its the right IP it is binding to the socket?

Maybe 'it is better to ask forgiveness than permission' ie try.,except

Yeah but the problem aint that I dont know if the server can create the socket. So I dont see any reason to use try and except.

The problem is that I connect to etc. xx.xx.xx.42 and then I also wants to bind that IP to the socket. But I dont know how to recall that IP, when I etc use gethostbyadress or anything else I get the main IP of the server that is xx.xx.xx.12

Hope that cleared what I asked about :)

Are you with me my friend? just loop on the ips and try/except, very easy ;)

you can also make a list of your ips and work your way out if you know what i mean.
You can even give any number of threads per ip.

now i got your problem understood.

using socket mean you must have a socket receiver/connecter at the other end for sync,

can you actually tell us what you want to achieve and perharps we can help you with a simple way out?

Sure. I want to be able to send a socket message with from a PHP script on my webserver with a HTTP header to a specific IP on the server.
Then the IP I call in the socket needs needs to bind it self to the webserver and send the message it recieves from my php script.
So kind of a proxy where I can be able to use all the IP's on the server if just I am able to recall the right IP again :)

I get you but it seems you are now confused. This is python forum.....

In all of this, you must have a running server to communicate with your sockets request.

Look , just write something dowm ok. Show us what you get so far ;)

Great i just checkup your link. very nice article.

But you can create the same stuff using threading and socket.
My problem is what are you trying to achieve? I am very curious.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.