Remote User's hostname + App Engine Python - python

Similar to:
remote_addr - The remote user's IP address.
self.request.remote_addr
Instead, is there a way to get the remote user's hostname ? Something similar maybe like,
self.request.hostname
As from the official document, The Request Class, doesn't seem to have the option to get the remote user's hostname.
I'm trying to uniquely identify a machine, with the combination of hostname+ip, because there are some users may share the internet gateway, thus having same IP address is possible and that would make ip address not unique enough.
Any advice on this ? or at least, could anyone suggest alternative way to uniquely identify an machine with anonymous identity ?

No, there's no way to do reverse DNS lookups on App Engine, and the information is not supplied by HTTP or the App Engine environment. Further, this wouldn't help you, for a couple of reasons:
The reverse DNS will be the same for every user with a given IP, since it depends only on the IP.
Anyone who has control over their reverse DNS can set it to anything they like.

I don't think this is possible over HTTP.
Generally, cookies are used for this purpose.

Related

Access django main page by its name not ip

is there a way to configure a Django server in that way so I can open my local webpage by typing 'weatherstation.local' and not by the IP:port?
in your router you might be able to set DNS. if DNS administration exists, then here you can set different domain names for IP addresses on your network.
You can give your ip address multiple domain names, and then you can use somthing like NGINX to route the domain calls to different services that you are running on your server.
Good luck, I hope this was helpful ;-)

How do I get the client port number in a Django project?

I am using django to build my web server, other people connect to me as clients. Now I need to know the clients' port number to distinguish them. If their browser opens two 'Tabs' of the same link, i.e. two pages but the same link, I also have to distinguish them.
Although I know I can use request.META['REMOTE_ADDR'] to get the client's IP in my django view function, but this realy is not enough for me.
Then I studied some TCP/IP basics and then I know that in TCP/IP layer, every IP packet has an IP header which contains the client's port number. But how can I access it in django?
Additional info:
I'm using python 2.6 and django 1.4
I know every TAB of a browser will be allocated a random unique port to access my django web page port. -- see this link 'The web server opens port 80, but the browser has a different, randomly-assigned port.' I really need to distinguish them. So my intuitive thoughts is to use the port number in the IP packet. If you have any other suggestion, also welcome.
I have found the similar question here, but I am not using Apache now. And this may be hard for me to config so maybe causing other more complex questions. This might make this simple question complex.
while I debug the django , I find this
request.environ["wsgi.input"].raw._sock.getpeername()
maybe it can work
Yes, after days of struggling, I answer it, with a working, but ugly solution on 'how to get client port in Django'.
in your python26/Lib/SocketServer.py, find def process_request_thread,add
global gClientPort; gClientPort = client_address
use this global value in yout project. Its format is ('12.34.56.78',55437) for example. 55437 is the port number.
Your assumption about 'every user connection opens connection at unique port' is wrong. All users are using the same port to connect.
To distinguish users Django (and almost every other frameworks) is using sessions. Every user gets a cookie with his unique session ID, and this cookie is passed to a server on every connection, so the application can distinguish users.
Here is documentation on sessions:
https://docs.djangoproject.com/en/1.8/topics/http/sessions/

Bitcoinrpc connection to remote server

Hey I was wondering if anyone knew how to connect to a bitcoin wallet located on another server with bitcoinrpc
I am running a web program made in django and using a python library called bitcoinrpc to make connections.
When testing locally, I can use bitcoinrpc.connect_to_local), or even bitcoinrpc.connect_to_remote('account','password') and this works as well as long as the account and password match the values specified in my 'bitcoin.conf' file. I can then use the connection object to get values and do some tasks in my django site.
The third parameter in connect_to_local is default localhost. I was wondering:
A) What to specify for this third parameter in order to connect from my webserver to the wallet stored on my home comp (is it my IP address?)
B) Because the wallet is on my PC and not some dedicated server, does that mean that my IP will change and I won't be able to access the wallet?
C) The connection string is in the django app - which is hosted on heroku. Heroku apps are launched by pushing with git but I believe it is to a private repository. Still, if anyone could see the first few lines of my 'view' they would have all they need to take my BTC (or, more accurately, mBTC). Anyone know how bad this is - or any ways to go about doing btc payments/movements in a more secure way.
Thanks a lot.
I'm currently doing something very similar (heroku using express/nodejs instead of django/python tho) so I will try to share my thoughts.
In spite of using other library and other language, all the wallet remote libraries should be primarily a wrapper around JSON RPC (remote procedure call) API, which is actually the same for most of the coins out there (i would say all, but that would be a wild guess).
Specifically to your questions:
A)
To access the wallet from outside, use your external ip (fastest way to find it is to query google for it). Depending on your ISP you hopefully have static external address. You must provide this address to bitcoin.conf file under rpcallowip= option to allow incomming connections.
Moreover you should forward the used port in your home router (usually under NAT settings) to your local machine so the incoming connection from the server is allowed and redirected to your wallet computer.
There is one important thing to consider (https://en.bitcoin.it/wiki/Running_Bitcoin):
By default, only RPC connections from localhost are allowed. Specify
as many rpcallowip= settings as you like to allow connections from
other hosts (and you may use * as a wildcard character).
NOTE: opening up the RPC port to hosts outside your local
trusted network is NOT RECOMMENDED, because the rpcpassword
is transmitted over the network unencrypted.
I am yet to look into it further, from this comment alone it seems totally unusable for monetary transactions.
B)
As I said before, it depends on your home ISP, type of connection and the service provided to you.
C)
If I understand correctly from a django point of view, as long as the login parameters (username/password) are inside a view (views.py of your app) and the debug mode is turned off, source code of the server should not be publicly accessible. But the security concern from A still applies.
You can use SSL with RPC to hide the password.
rpcssl=1

Overriding hostname IP address in qtwebkit request

I'm downloading a web page (with PyQt4/QtWebKit) using given hostname, but I would like to use a pre-defined IP address for that hostname. For example, I need to hit "http://www.mysite.com" but use the IP address 1.2.3.4 instead of the actual resolved IP address. Is this at all possible in QtWebKit? I've tried a couple things so far:
Hitting http://1.2.3.4/ and sending a "Host" header of "www.mysite.com". This almost works, but ends up failing for a number of reasons (I'd be happy to go into more detail here).
Using a global /etc/hosts setting. This didn't work because it is hard to automate and I will be doing multiple downloads at once.
Is there a way to either in python or in PyQt4/QtWebKit to override the IP address associated with a hostname?
This is big for me. Any help at all would be greatly appreciated.
Use custom network access manager, something like this (C++): http://ariya.blogspot.com/2010/05/qnetworkaccessmanager-tracenet-speed.html, so that you can "hijack" the network request and "redirect" it to other domain.

IP address of domain on shared host

I have domain on a shared hosting provider. How do I find the direct IP address of my domain using Python?
Is it possible to post to a script on my domain using the IP address and not the website itself?
Thanks.
I guess the IP should be static so do you really need to look it up more than once?
You need to specify the domain name so that the webserver knows which host configuration to use if you don't have a dedicated IP or your host is the default for that webserver
import socket
socket.gethostbyname("www.stackoverflow.com")
'69.59.196.211'
will get you the ip address (as a string) of your domain.
However, if it's shared hosting I would think it highly unlikely that you'll be able to access your hosting via the ip - most likely you'll have something like Apache's VirtualHost Directive in place which limits you to only 'seeing' requests to your domain. Requests to the IP address will be served by some default configuration.
Would very much depend on the nature of your hosting.
A curious request ...
To look up a domain name, do something like this:
import socket
ipaddress = socket.gethostbyname('www.bbc.co.uk')
Regarding posting to the IP address:
I don't think it would work in the normal way (like from a browser), because there will probably be many sites held under that address.
But, I guess you could do it in a very manual way, using a programming language (e.g. Python), if you connected a client socket to the site's IP address, but still sent the website's name in the HTTP Host request header.
I don't know if that poses more questions than it answers, and I don't know why you'd want to do either of the above, but there it is.
Good luck!

Categories