user2629904
user2629904

Reputation: 13

Get response from an ip address in python


Given an ip, how can i make an http request to this ip in python?

For example, if i want to get a file names 't1.txt' from the server that resides on '8.8.8.8', how can i do so? I've tried using httplib and urllib2. (It's better if the proper way will be by using standard Python libs).

Thanks a lot, Iko.

Upvotes: 1

Views: 1693

Answers (2)

Sylvain Leroux
Sylvain Leroux

Reputation: 51980

For simple url retrieval, urllib is perfectly OK (and is a standard Python library)...

... but if you are looking for something more easy to use in more complex cases, you should take a look at request:

import requests
r = requests.get('http://8.8.8.8/t1.txt')

Upvotes: 2

Freelancer
Freelancer

Reputation: 4770

import urllib
urllib.urlretrieve ("http://8.8.8.8/t1.txt", "t1.txt")

Upvotes: 4

Related Questions