[Resolved] Extract hosts.csv with script python3
-
Hello,
How i do to download hosts.csv in script python3
I try something like thatimport requests import csv import shutil Login = "fog" Pass = "bar" site ="http://IP/fog/management/index.php" headers = {'User-Agent': 'Mozilla/5.0'} payload = {'uname': 'fog', 'upass' : 'bar', 'ulang' : 'English'} payload2 = {'fogguiuser' : 'fog', 'fogguipass' : 'bar', 'nojson' : ''} s = requests.Session() r = s.post(site + "?node=home", headers=headers, data=payload) t = s.get("http://IP/fog/management/index.php?node=host&sub=export") page = t.text print ("[+] Connexion OK") r = s.post(site + "/export.php?type=host", headers=headers, data=payload2) with open('test.csv', 'wb') as f: print ("[+] Récupération du csv") t = s.get("http://IP/fog/management/index.php?node=host&sub=export", stream = True) print (t.text) print ("[+] Enregistrement terminé") f.write(t.content) f.close()
Don’t work :"(
Have you an idea ?
thxs -
@Crok Three things need adjustment in your script.
- Add empty
login
param to the initial site logon request
payload = {'uname': 'fog', 'upass': 'password', 'ulang': 'English', 'login': ''}
- Use different URL for the later export POST request and write CSV data without another GET request
r = s.post("http://IP/fog/management/export.php?type=host", headers=headers, data=payload2) with open('test.csv', 'wb') as f: f.write(r.content) print ("[+] Récupération du csv") f.close()
Good luck!
- Add empty
-
Thxs for your response.
But i’m so bad :"(import requests import csv import shutil Login = "fog" Pass = "bar" site ="http://IP/fog/management/" headers = {'User-Agent': 'Mozilla/5.0'} payload = {'uname': 'fog', 'upass' : 'bar', 'ulang' : 'English', 'login': ''} payload2 = {'fogguiuser' : 'fog', 'fogguipass' : 'bar', 'nojson' : ''} s = requests.Session() r = s.post("http://IP/fog/management/index.php?node=home", headers=headers, data=payload) print ("[+] Connexion OK") r = s.post("http://IP/fog/management/index.php?node=host&sub=export", headers=headers, data=payload2) with open('host_export.csv', 'wb') as f: print ("[+] Récupération du csv") f.write(t.content) print ("[+] Enregistrement terminé") f.close()
Have you another advice ?
-
@Crok Three things I notice:
t = s.get("http://IP/fog/management/index.php?node=host&sub=export")
is still needed after the login- The second
s.post()
call needs to go to.../export.php?type=host
f.write(t.content)
should actually bef.write(r.content)
-
my script work \o/
#-*- coding: UTF-8 -*- import requests headers = {'User-Agent': 'Mozilla/5.0'} payload = {'uname': 'fog', 'upass' : 'bar', 'ulang' : 'English', 'login': ''} headers2 = {'User-Agent': 'Mozilla/5.0', 'Referer': 'http://IP/fog/management/index.php?node=host&sub=export'} payload2 = {'fogguiuser' : 'fog', 'fogguipass' : 'bar', 'nojson' : ''} s = requests.Session() r = s.post("http://IP/fog/management/index.php?node=home", headers=headers, data=payload) print ("[+] Connexion OK") s.get("http://IP/fog/management/index.php?node=host&sub=export") u = s.post("http://IP/fog/management/export.php?type=host", headers=headers2, data=payload2, stream = True) mon_fichier = open("C:\\my\\Path\\hosts.txt", "w") mon_fichier.write(u.text) mon_fichier.close() print ("[+] Enregistrement terminé")
thxs for your help.