Sending GET request for an IP address [duplicate] - python

This question already has answers here:
How to send http requests to flask server
(2 answers)
Closed 4 years ago.
I need to send a request to a web server of mine to start a stream. The web server is located at 0.0.0.0 (of course I can change the address).
How can I send a "GET" request to that server?
I already tried using httplib or urllib2 or 3 and they seem not to work with IP address.
I know that a local DNS server will map the address to a url, but that is not the goal to set up the server every time I want to execute the code in a new network.
Thank a lot.

You could use requests:
requests.get('http://0.0.0.0')
or even better
s = requests.Session()
s.get('http://0.0.0.0')
r = s.get('https://httpbin.org/cookies')
to keep the connection persistent, which is probably more like what you want.
See more about requests sessions at http://docs.python-requests.org/en/master/user/advanced/
Or you could just convert the IP address to a hostname using
socket.gethostbyaddr(ip) with urllib
to convert the IP address to a host name

It doesn't work because you probably haven't included the web protocol to use (i.e. HTTP or HTTPS). Try it like this
import urllib2
urllib2.urlopen('http://0.0.0.0')

Related

What is the best way to get a client ip in python? [duplicate]

This question already has answers here:
Get IP address of visitors using Flask for Python
(12 answers)
Closed 3 months ago.
I am building an application that requires the client ip for geolocation purposes. I am using python, flask, and nginx to serve. From what I have read, common ip address capturing happens in the actual server. Any python script I use inevitably just returns my servers ip. What is the best way to get a client's ip address and pass it to the python scripts for further work to be done?
Although you're required to share part of your code to get help, I'm gonna answer your question: You can use Flask request.
from flask import request
...
client_ip = request.environ['REMOTE_ADDR']
client_port = request.environ['REMOTE_PORT']

I want to change my ip address without using vpn or proxy

I scraping some pages and these pages check my IP if it is a vpn or proxy (fake IP) if it is found fake the site is blocking my request please if there is a way to change my IP every x time with real IP Without using vpn or proxy or restart router
Note: I am using a Python script for this process
You IPAddress is fixed by your internet service provider, if you reset your home router, u sometimes can take another IPAddress depending on various internal questions.
Some Websites, block by the User-Agent, IP GeoLocation of your request or by rate limit.. but if u sure its is by IP, so the only way to swap your IPAddress is through by VPNTunneling or ProxyMesh.
You can obtain free proxy address from https://www.freeproxylists.net/ . Since these are free proxies so it may get down quickly so sometime you might need to rotate ip with each request you made to your target address.
You can set proxy address, Please follow up this question, how to set proxy, Proxies with Python 'Requests' module
So the flow would be:
Scrape the proxies from above address first.
Then add the proxy header as mentioned in the another question.
Rotate Ip with another request to target.
There are certain blocking factor not only your ip.
Like browser agent (https://www.scrapehero.com/how-to-fake-and-rotate-user-agents-using-python-3/?sfw=pass1637120088).
Too rigorous scraping (try to randomize timing of scraping between two requests).
Not following up robots.txt file (this sometime cant be avoided).

is it possible to run multiple http servers on one machine? [duplicate]

This question already has answers here:
Can I run two web servers on the same computer?
(7 answers)
Closed 2 years ago.
can i run multiple python http servers on one machine to receive http post request from a webpage?
currently i am running an http server on port 80 and on the web page there is a HTML form which sends the http post request to the python server and in the HTML form i am using the my server's address like this : "http://123.123.123.123" and i am receiving the requests
but i want to run multiple servers on the same machine with different ports for each server.
if i run 2 more servers on port 21200 and 21300 how do i send the post request from the HTML form on a specified port , so that the post request is received and processed by correct server??
do i need to define the server address like this : "http://123.123.123.123:21200" and "http://123.123.123.123:21300" ?
Yes can run multiple webservers on one machine.
use following commands to run on different ports:
python3 -m http.server 4000
4000 is the port number, you can replace it with any port number here.

HTTP Client: What should it do when multiple A records for a domain?

I’m writing an HTTP client, and wondering how it should behave when there are multiple A records for a domain.
For example, say a second concurrent connection request to a given domain is opened. Should it use another IP address? How about on connection error, should it try another IP automatically? Should
it “remember” an IP failed for later requests, and try others first?

How to access parse.com REST API after migrating to local server?

I have been using parse as my project server and now that I have migrated the data to local server, successfully made dashboard work; but I cannot find a way to access api.parse.com/1/ API.
I used to use python to make REST requests and it is basically establishes socket connection with api.parse.com at port 443. Now I am trying to connect to localhost at port 1337 which is where the parse-server instance is running. However, I have not been able to access the API same as before.
One thing to note is that I can successfully curl to get basic JSON response from requests like
curl -X GET -H ... http://localhost:1337/parse/classes/_User
The question is which connection now replaces api.parse.com for locally held parse-server instances?
Ahh I found out the answer:
You make socket connection with address and port where the parse-server is running, and then instead of doing
conn.request("GET", "/1/login?%s"%...)
You do:
conn.request("GET", "/parse/login?%s"%...)
Hope this helps.

Categories

Resources