• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    [Resolved] Extract hosts.csv with script python3

    Scheduled Pinned Locked Moved
    General
    2
    5
    527
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Crok
      last edited by Crok

      Hello,
      How i do to download hosts.csv in script python3
      I try something like that

      import 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

      1 Reply Last reply Reply Quote 0
      • S
        Sebastian Roth Moderator
        last edited by

        @Crok Three things need adjustment in your script.

        1. Add empty login param to the initial site logon request
        payload = {'uname': 'fog', 'upass': 'password', 'ulang': 'English', 'login': ''}
        
        1. 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!

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        1 Reply Last reply Reply Quote 0
        • C
          Crok
          last edited by

          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 ?

          1 Reply Last reply Reply Quote 0
          • S
            Sebastian Roth Moderator
            last edited by Sebastian Roth

            @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 be f.write(r.content)

            Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

            Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

            1 Reply Last reply Reply Quote 0
            • C
              Crok
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post

              160

              Online

              12.0k

              Users

              17.3k

              Topics

              155.2k

              Posts
              Copyright © 2012-2024 FOG Project