Jump to content
adonisslanic

Citire texte de pe un site

Recommended Posts

Am o problema in Visual Basic 2008...

Vreau sa stiu si sa inteleg cum se pot citi datele dintr-un fisier .txt care se afla pe un site de-al meu...Stiu cum se citesc fisierele din calculator, dar vreau sa fac acelasi lucru si cu fisierele de pe internet... Ca am mai vazut un cititor pe hackthissite.org la misiuni cu cracking, si am observat ca folosea winsock... Va rog mult ajutati-ma si dati-mi un cod ceva... :confused:

Link to comment
Share on other sites

WebRequest req = WebRequest.Create("adresa site");

WebResponse response = req.GetResponse();

Stream stream = response.GetResponseStream();

private byte[] downloadedData;

byte[] buffer = new byte[1024];

MemoryStream memStream = new MemoryStream();

downloadedData = new byte[0];

while (true)

{

int bytesRead = stream.Read(buffer, 0, buffer.Length);

memStream.Write(buffer, 0, bytesRead);

}

downloadedData = memStream.ToArray();

stream.Close();

memStream.Close();

FileStream newFile = new FileStream(@"C:\zTmp.txt", FileMode.Create);

newFile.Write(downloadedData, 0, downloadedData.Length);

newFile.Close();

Link to comment
Share on other sites

Sau in python:

1) Salvezi in ufr.py script-ul:

#! /usr/bin/env python
# 05.07.2009 <> 05.07.2009 | cmiN
# URL-File-Reader 4 adonisslanic @ rstcenter.com


import os, sys, urllib2, urlparse


def main():
args=sys.argv
if len(args) != 2:
print("\tUsage:\n\n\
\tufr.py http://www.site.com/path/file\n\n\
Press any key to exit. . .\n\n\n")
else:
print("Please wait...\n\n")
url=args[1]
splited_path=urlparse.urlsplit(url).path.split("/")
filename=splited_path[len(splited_path)-1]
sock=urllib2.urlopen(url)
source=sock.read()
sock.close()
f=file(filename, "w")
f.write(source)
f.close()
print("Ready! Check %s." % filename)


if __name__=="__main__":
try:
main()
except:
print("Invalid URL or timed out!")
os.system("pause >NUL")

2) Start -> Run -> cmd -> cd %locatie% unde %locatie% este path-ul unde se afla ufr.py

3) ufr.py -> vezi usage

Citeste orice fisier de tip ASCII din URL, URL care poate folosi orice protocol http/ftp/etc si ii salveaza datele intact intr-un fisier cu numele si extensia celui citit din URL in acelasi folder unde se afla si script-ul.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...