How to setup a client server without localhost using python - python

I am very novice with socket programming so sorry about any simple questions
My objective is to create a server which sends to several clients a csv file, clients located in different locations
I have a question about the following initial part of server and client
#TCP_IP = 'localhost'
TCP_IP = socket.gethostbyaddr("myip?")[0]
TCP_PORT = 9001
When debugging that line I get a valid isp domain but
If I do it this way I get an error that the Address is not valid
Shouldnt I place my real static ip in server script and in client script?

Related

How can I make my client and server IPv6 compatible? (Flutter, Python, Nginx)

I have a mobile app that sends location information to database. The server (Tavu.io) is Ubuntu based and uses Nginx. The problem is that when I try to connect to the server using IPv6 address, the data is not transferred. The application should work in IPv6 network only. UDP protocol should be used.
In the nginx.conf, there are path to files included that contain:
listen 80 default_server;
listen [::]:80 default_server;
netstat -pnltu shows that "tcp" and "tcp6" have LISTEN. But, there is only "udp", and no "udp6" which I assume it should be. There is no LISTEN on "udp".
My Python socket is like this:
self.connection = db.connect_to_database()
self.status = True
self.udp = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)
self.udp.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
self.udp.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
self.udp.bind(('', 50943))
And the mobile client (Dart/Flutter):
static String serverIP = '[ipv4 address hardcoded]';
static Future<RawDatagramSocket> rDgS =
RawDatagramSocket.bind(InternetAddress.anyIPv4, 50943);
rDgS.then(
(RawDatagramSocket udpSocket) {
udpSocket.writeEventsEnabled = true;
List<int> data = utf8.encode(message);
udpSocket.send(data, InternetAddress(serverIP), 50943);
},
);
That above code works at that state as intended, but when is use hardcoded IPv6 address and change to .anyIPv6, the sent data is not reaching the server. No error is shown on the VSCode console though. The reason the IP addresses are hard coded because I don't have the hostname for the server and giving server name to nginx.conf was not working. Is there a workaround to this issue to have client to connect to server while in IPv6-only network?
I have changed the settings on nginx and attempted multiple times this application on IPv6-only network but the data (location and username) are not sent to database.

How to get the Current User IP in Python / Django

I am trying to capture the IP Address and the System Name of the current Login user during the login Process.
I Use following code for the same:
import socket
system = socket.gethostname()
IPAddr = socket.gethostbyname(system)
It works fine in Local Server but when I push to Server it takes the server name and server IP instead of user IP.

XMPPPY unable to connect to the server

I am using xmpppy python library to connect with XMPP server(ejabberd2) but unable to connect and actually don't have clarity on how to connect, authenticate and send a message to the server.
Please help me to make it working
If possible please provide some code snippet using XMPPPY.
I figure out the solution with the help of a friend
It requires change the in XMPP ejabberd server config.
Change the line {hosts, ["localhost"]} with {hosts, ["localhost", "server-domain", "server-ip-address"]} in the ejabberd.cfg file.
Restart the server and create another user under new hosts with the server domain or server ip.
Code snippet:
import xmpp
ipaddress='<server-ip>'
user='<new-user>' #without #<server-ip>
passwd='<password>'
c = xmpp.Client(ipaddress)
c.connect((ipaddress,5222), secure=0)
c.auth(user,passwd,sasl=1)
c.sendInitPresence()
c.isConnected()
c.send(xmpp.protocol.Message('<jid of receiver user with #<domain> >',"hello world"))

about get client ip address in python CGI

I am trying to get the original client ip address in a python cgi script. The client connect to the web server with a proxy. Following code always returns the proxy ip address. I tested all the env variable, HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR all return None. Is there any other way to get the client ip behind a proxy? like can I read the http header in a python cgi?
ipaddr = (getenv("HTTP_CLIENT_IP") or
getenv("HTTP_X_FORWARDED_FOR") or
getenv("REMOTE_ADDR") or
"UNKNOWN")
Do you want to:
find the client's IP address in the headers
use some sort of javascript to tell you?
For the former, you need the proxy to give you the client address.
Have you tried cgi.print_environ_usage() and looking for the IP address?

In need of a python script to upload a file with IP address every few minutes

I'm using windows server 2008, and one of the things I need to do in order to pair to a domain name is send a file with the computers current IP address (it's not static) to a server via sftp every few minutes. The problem is that I'm not sure how to do this.
I would send it via XMPP. You can set up a listener service for the server.
Send an xmpp message using a python library
Here are some ideas on XMPP servers to run on your IIS server (listening to recieve the incoming messages from clients http://metajack.im/2008/08/26/choosing-an-xmpp-server/
Pretzel looks nice
this python code can be run client side to get the public IP address.
host, aliaslist, lan_ip = socket.gethostbyname_ex(socket.gethostname())
print host
print aliaslist
print lan_ip[0]
Than you would send via XMPP message containing the IP to the server you have set up on your IIS server. Depending on what you want to do with the IP address once it gets to the server, you will handle the message serverside

Categories

Resources