Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (2)

Powered by Vanilla. Made with Bootstrap.
Subnet loop
  • Orgy
    Posts: 40
    Pretty simple code. Insert an integer, such as 66, and it will loop through 66.0.0.0 to 66.255.255.255, storing them each line by line in a text file.
    <?php
    set_time_limit(0);
    $errorArr = array();
    if (!isset($argv[1]))
    {
    array_push($errorArr, \"You didn't enter a subnet to loop through.\n\");
    }
    if (isset($argv[1]) && !is_numeric($argv[1]))
    {
    array_push($errorArr, \"The first argument needs to be an integer.\n\");
    }
    if (isset($argv[1]) && ($argv[1] > 255 || $argv[1] < 66))
    {
    array_push($errorArr, \"The entered subnet is outside of the recommended limit.\n\");
    }

    if (!empty($errorArr))
    {
    echo \"Your syntax is incorrect:\n\";
    foreach ($errorArr as $errorStr)
    {
    echo $errorStr;
    }
    die(\"Proper syntax is: php {$argv[0]} <subnet>\n\");
    }

    $startIP = \"{$argv[1]}.0.0.0\";
    $exIP = explode(\".\", $startIP);

    while (1)
    {
    $exIP[3]++;
    if ($exIP[3] == 256)
    {
    $exIP[2]++;
    $exIP[3] = 0;
    }
    if ($exIP[2] == 256)
    {
    $exIP[1]++;
    $exIP[2] = 0;
    }
    if ($exIP[1] == 256)
    {
    break;
    }
    }

    ?>
  • undead
    Posts: 822
    I'll study that. Thanks for sharing.
  • Orgy
    Posts: 40
    No problem. Not much to study, though. Just something I whipped up real quick this morning for an exploitation system I'm working on. If you have some questions, feel free to ask.
  • Xin
    Posts: 3,251
    Nice little code, this can easily be modified to perform a ping sweep which can be very useful :)
    Xin
  • Orgy
    Posts: 40
    I only wish that PHP supported threading =[