-2

I need to read the remote file content using python but here I am facing some challenges. My code is below:

import subprocess

path = 'http://securityxploded.com/remote-file-inclusion.php'
subprocess.Popen(["rsync", host-ip+path],stdout=subprocess.PIPE)
for line in ssh.stdout:
    line  

Here I am getting the error NameError: name 'host' is not defined. I could not know what should be the host-ip value because I am running my Python file using terminal(python sub.py). Here I need to read the content of the http://securityxploded.com/remote-file-inclusion.php remote file.

halfer
  • 19,824
  • 17
  • 99
  • 186
satya
  • 3,508
  • 11
  • 50
  • 130
  • What do you mean by `host-ip+path`? Anyway, take a look at [`requests`](http://docs.python-requests.org/en/master/) – bereal Jul 24 '17 at 06:33
  • 1
    Try `urllib` have a look [this](https://stackoverflow.com/questions/15138614/how-can-i-read-the-contents-of-an-url-with-python) question – mkHun Jul 24 '17 at 06:34
  • Possible duplicate of [How can I read the contents of an URL with Python?](https://stackoverflow.com/questions/15138614/how-can-i-read-the-contents-of-an-url-with-python) – bereal Jul 24 '17 at 06:34
  • @bereal : I just gave one example but my need is how to read the remote file content. – satya Jul 24 '17 at 06:35
  • @satya Mean.? Do you want to connect the remote server? – mkHun Jul 24 '17 at 06:39
  • @mkHun : yes my need is to test the `remote file Vulnerabilities` by including the remote files. – satya Jul 24 '17 at 06:45

2 Answers2

1

You need the urllib library. Also you are using parameters which you don't use. Try something like this:

import urllib.request

fp = urllib.request.urlopen("http://www.stackoverflow.com")
mybytes = fp.read()

mystr = mybytes.decode("utf8")
fp.close()
print(mystr)

Note: this is for python 3

For python 2.7 use this:

import urllib

fp = urllib.urlopen("http://www.stackoverflow.com")
myfile = fp.read()
print myfile
1408786user
  • 1,868
  • 1
  • 21
  • 39
0

if you want to read remote content via http.

requests or urllib2 are both good choice.

for Python2, use requests.

import requests
resp = requests.get('http://example.com/')
print resp.text

will work.

HolaYang
  • 419
  • 2
  • 10