Flask:Python - How to check IP address of the request [duplicate] - python

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Get ip address of visitors using Python (specifically Flask micro-framework)
I'm creating REST api with flask. I want to allow requests only from one (or more later on) IP addresses. How do I check for IP address in my view?

Get the headers from Incoming Request Data and find the REMOTE_ADDR

if you are using google app engine you would use self.request.remote_addr

Related

get the source IP address of a tcp connection request [duplicate]

This question already has answers here:
Refusing connection from a host
(4 answers)
How to find the source ip and port of a client that wants to connect to a listening socket?
(2 answers)
Getting the source IP address of incoming connection
(1 answer)
Deny a client's TCP connect request before accept()
(1 answer)
Closed 7 months ago.
so assume I have a socket called S, it's listening for tcp requests
IP address X sent a connection request, at this stage I have the option to accept it, but first I want to just print the IP address
there is no error I straight up don't have the slightest idea on how to do this, I tried googling, went thru the docs, nothing was of any help, thanks in advance guys

How to specify source IP address in python requests [duplicate]

This question already has answers here:
Requests, bind to an ip
(3 answers)
Closed 8 months ago.
I have several IP addresses configured on my network interface card. I need to specify through which IP address python requests must connect to the web server. Is it possible?
import requests
r = requests.get("http://example.com/foo/bar")
I need to force requests.get to perform http request through a dasignated IP address.
Is there any other http library that support this feature in python?
Are you running a Django/Django-Rest project? Because, if so, you can just specify a custom host and port into the python manage.py runserver command! Like so:
python manage.py runserver 0.0.0.0:8001
Hope I understood the problem
You can use a SourceAddressAdapter from requests-toolbelt:
import requests
from requests_toolbelt.adapters import source
source = source.SourceAddressAdapter('127.0.0.1')
with requests.Session() as session:
session.mount('http://', source)
r = session.get("http://example.com/foo/bar")

Python: Retrieve the Mac Address of the client using bottle framework [duplicate]

This question already has answers here:
How to get Client Machine's Mac Address in a Web application
(3 answers)
Closed 7 years ago.
I am looking to retrieve the Mac_Address of the user accessing my application.
I have tried the following code:
import uuid
from uuid import getnode as get_mac
mac_address = get_mac()
mac_address = ':'.join(("%012X" % mac_address)[i:i+2] for i in range(0, 12, 2))
This works OK but returns the mac address of the server and not the client. Is there a way to retrieve the mac address of the client?
The HTTP protocol does not send the MAC address of the client to the server, so there's no way for your server-side application to access it.
The client's MAC address is never revealed to the outside network. Thus it is not possible to get it. The only way for it is to install your app on user's machine.
You will only be able to retrieve the MAC address of users who happen to be on the same LAN network segment as you are, so it is probably not a good idea to bake in the assumption that you can rely on the user's MAC address being available.

python automatic email response system [duplicate]

This question already has answers here:
Receive and send emails in python
(10 answers)
Closed 7 years ago.
I am planning to create a program(with python) that analyzes and responds to emails on ubuntu, but I cant seem to find anything that could serve as the receiving and sending part of the program(in python, or with terminal commands) does anyone have any suggestions on what I could use?
You can use the libraries
poplib and imaplib for receiving emails,
smtplib for sending emails,
have a look at email to compose more complex emails.
You want to take a look at poplib and smtplib.

HTTP requests using multiple IP addresses on python [duplicate]

This question already has an answer here:
HTTP Requests using a range of IP address on python
(1 answer)
Closed 8 years ago.
I'm writing a python script that will send http requests concurrently to the urls mentioned in a file using python. The script works fine for a single IP address. The OS I'm using is linux. I've generated virtual IP addresses like eth0:1,eth0:2 etc. I want to send HTTP requests using these virtual IP addresses along with the eth0 IP address concurrently. I use the requests module for http requests and threading module for concurrent requests. Kindly help me. I'm trying to develop a web testing tool.
I think you wanted to avoid "Crawl Delay" and do faster crawl on one server!
In this case, Remote Web Server will recognize request from only one IP!!
I think using parallel + curl + python script is more simple and best way.
or use https://pypi.python.org/pypi/pyparallelcurl/0.0.4
or use a lot of servers.
and refer to https://code.google.com/p/httplib2/issues/detail?id=91

Categories