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

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

Related

Run flask file on wlan1 instead of wlan0

I have a raspberry pi, a flask server, a flask client, and two different networks.
when I connect a wifi adapter to the raspberry pi I can see that I have a new interface called "wlan1" is there a way to run a the server for example on "wlan0" and the client on "wlan1".
what I'm trying to do is run the server on a different network than the client (while both of them are on the pi).
Server:
For the server part, you need to "bind" the listening socket to the IP address of wlan0.
Find the IP address of wlan0 using ifconfig wlan0 or ip addr show dev wlan0 (e.g. 192.168.0.2)
Bind the Flask server to that IP address using app.run(host='192.168.0.2', port=80)
If you bind to 0.0.0.0, it will be reachable from all network devices.
Client:
A little bit more involved, take a look at how "routing tables" work for the theory.
Find out the IP address of the server that your client will connect to (e.g. 93.184.216.34)
Find out the IP address of the default gateway on the interface wlan1, for example with ip route (look for "default via dev wlan1"), e.g. "default via 192.168.1.1 dev wlan1"
Add a route to that IP address via the gateway and interface, using route add 93.184.216.34 gw 192.168.1.1 dev wlan1
Note that the routing table will affect all programs on the raspberry pi, not just your client application.

How to get the ip address of a request machine using python (On Sanic)

I am trying to get the IP address of the requesting computer on my server. I can successfully get the IP-address from request header if the request came from a web browser. The code example below. However, I cannot fetch the client IP, if I send the request via curl/postman. I checked the nginx log, and I found there is a log of my public IP when I sent a curl request. How can I achieve this?
PS: I am using the Sanic Framework.
client_ip = request.headers.get('x-real-ip')
In sanic's docs for Request Data:
ip (str) - IP address of the requester.
Therefore, just use
client_ip = request.ip

How to setup a client server without localhost using 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?

DNS requests over ICS (Internet Connection Sharing)

Recently i implemented i small captive portal in python. i redirect users to the login page from dns requests. All worked fine until i realised when dns server i manually change on client system to a public dns, it totally bypass the captive portal. My problem is, how to redirect users even with dns servers changed or how to block all outgoing dns requests which is not using the default dns.
I was thinking listening on port 53 would capture all request using twisted.
This is a very simple example of how i am doing it:
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor`
class UDP(DatagramProtocol):
def datagramReceived(self, datagram, addr):
print datagram, addr
port = 53
max_byte = 512
reactor.listenUDP(port, UDP(), '', max_byte)
reactor.run()
Am i doing it wrong?
I also tried to block remote port 53 from the firewall on the main machine providing Internet connectivity but it also doesnt work.
If users are bypassing your captive portal by changing DNS, the issue is that they can route DNS requests around the portal, and therefore there's nothing you can do in the portal. You need to create routing rules which redirect all port 53 traffic on your network to your DNS server, regardless of where they're trying to send it.
The bad news is, you can't do this with Twisted. You need to do this in your router's operating system, using something like iptables.

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?

Categories

Resources