Returning Local Directory Listing

Discussion in 'PHP' started by Jaxo, Nov 22, 2011.

  1. #1
    Hey DP!

    I've been a long-time lurker, so you might not know me ;)

    But I have finally encountered a problem in my script. The rest of the program works fine, except for this one part.

    My program scans for IPs on your LAN, and returns the IPs found with webservers. This all works great. However, I want to add a directory listing feature, where you can view a directory listing of that IP.

    I know that glob("*"); would work perfectly for this, but that code would only return the current files in the directory the code is running from. How can I do something similar to glob("*") on an IP that is still on my network (192.168.0.207 is my machine, I want to get the listing for 192.168.0.1, my test server)?

    I've looked at fsockopen() quiet a bit, but it seems like a completely different language to me. Rarely have I used functions like fgets(), where you need to specify the amount of bytes to grab (or something?)!

    Thank you!

    -Jaxo
     
    Jaxo, Nov 22, 2011 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Are you running Linux? You could use shell_exec in conjunction with wget.
     
    Alex Roxon, Nov 23, 2011 IP
  3. Jaxo

    Jaxo Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Sorry for the late reply!

    Yes, I am running Linux. However, I tried what you said and it just ended up downloading the target into a directory. Of course, then I could just loop through the directory, but I'd rather not make the server download every single file. Also, it won't download .php files, with their PHP variables and code inside. I should be able to do this though, because the files are still on my local network, right?
     
    Jaxo, Nov 26, 2011 IP
  4. thinglet

    thinglet Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Are you speaking of a SMB directory/file listing or an HTTP directory/file listing?
     
    thinglet, Nov 26, 2011 IP
  5. Jaxo

    Jaxo Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    It's an HTTP directory, the very same thing you'd get if you entered a directory in a web browser without an index.*
     
    Jaxo, Nov 26, 2011 IP
  6. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #6
    Well, I mean, you can't just list the directory contents of a remote server. Think of all of the security related problems that would occur if you could. Your best bet is to set up some form of PHP or bash script on the remote server that you can communicate with.
     
    Alex Roxon, Nov 26, 2011 IP
  7. Jaxo

    Jaxo Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Ah, that's true. I've had this problem in the past, too, and I ended up doing something like that.

    This time I assumed, since it's local, it would be different. But I guess if the script isn't executing from that IP, you can't execute code as if it was.

    Thanks for all your help, guys!
     
    Jaxo, Nov 26, 2011 IP