Python Pyro4 - Get client IP - python-3.x

I want the server to get the caller's IP in any way. E.g. client calls function on server that checks his IP.
Also I want to know how to get my own external IP using pure Python or built-ins.

Answers are in the manual.
Pyro4.current_context
Pyro4.socketutil.getIpAddress

Related

Using socket module in website integrated python 3 IDE

import socket
a = socket.gethostbyname(socket.gethostname())
print(a)
When I run this code in the IDE in my pc, it shows the Ipv4 address of my pc.
But when I run this code in the integrated IDE in sololearn, it shows some other Ipv4 address but not mine. How to modify the code to show the Ip address of the user and not the server?
socket.gethostname()
Return a string containing the hostname of the machine where the
Python interpreter is currently executing.
Note: gethostname() doesn’t always return the fully qualified domain
name; use getfqdn() for that.
I've never heard of sololearn, but the python documentation is crystal clear on this one. It's possible your local name resolver is configured strangely, but that is beyond the scope of this question.

how to create ip alias in nodejs

I am writing test in nodejs.
Calling my api using requestjs.
Now I have to make one call using an ip address to the api (/resources/media)
Then I have to make another call to the same api (/resources/media) using different ip from the same computer.
OS: ubuntu
any idea how to do that
help is very much appreciated.
Thanks
Your only choice is to set up a proxy (like squid), bind it to another (virtual) networking interface card and make the second request through it.
add another ip and make sure it was not existed before
sudo ip addr add 192.168.50.5 dev eth1
Then user localAddress option in requestjs

Finding server in LAN

How to find, in python, server without having it's IP in LAN?
I assume that port will be configured in file so its doesn't have to find port. I tried to search on google but I couldn't find anything useful or that could help me with it.
The server IP will be changing because it will not run constantly on the same computer.
So basically I got app with server that is on random computer in network, and I want to find its IP from another computer.
I would be really thankful for either explanation how to do it or link that could help me to do it.
Not certain if this is what you want to do, I think you want to find the IP of a server by running some python execution on the server?
You could try :
from subprocess import call
call (["ipconfig"])
This will dump the IP config and you can parse out the IP address. This assumes a windows server. You would have to modify the call for your OS.
Updated :
Check this out : TCP Communications or UDP Communications ... it looks like what you are looking for. You will still have the mess of determining the available addresses on the network (arp -a), and testing each one - this would be your client side app. Your server side app, when it receives the right query on the TCP or UDP port, would then determine it's address (ipconfig) and return the value.

How to connect to remote linux server in the same network but with different IP address through Python Script

I am trying to use socket or ssh module to connect to remote linux server in the same network but with different IP address through Python Script to retrive values of files from it.
But I am not able to get extact methods and the code is not working. Can anybody help me with this.
Don't use the raw socket library. Instead, use the paramiko library to establish an SSH connection to the second linux server.
Their site contains excellent examples of usage.

Same server, same program but started once using one network card and after with another

I have a Linux server with multiple ips (so, multiple eth0, eth0:0, eth0:1 etc).
The script I'm trying to start is a php CLI script which is downloading stuff from an another server API, and I would like to change the IP based on different parameters. Once the script is started, I don't need anymore to change the ip OF THAT SPECIFIC script until his end.
Do you have any clue if it is possible to achieve it?
My other solution was to install Xen or OpenVZ and create N different VPS per each IP, but as you can see is definitely a PITA :-)
You don't specify how you connect to the other server, but with sockets you can try socket_bind.
EDIT:
With curl you can try curl_setopt.
CURLOPT_INTERFACE The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.
I know how to do it in C - you use bind() on your socket before you call connect(), and you bind to the IP address assigned to the desired interface, passing 0 for port. I don't know how to do it in PHP.

Resources