1

I am trying to do a dynamic inventory of machines (workstations) on a very large company with tons of security, firewalls, ports disabled, etc.

The only thing I've seen available across the property is the availability of ping so I think this is the best way to approach for a solution.

I was thinking about doing a batch script from my windows workstation but knowing nothing about batch scripts will add a learning curve period to my project.

What I have experience with is PHP and I know there's a function to call system functions. I googled it an several people were having problems getting a valid output from the system function.

My concrete question would be, how would you approach a solution for this having:

  1. a txt list of all the machine names
  2. ping availability
  3. php server ready to go and configurable in case I need to turn off the safe mode or anything like that.

Thanks for your feedback.

Julian
  • 17
  • 6
  • With a windows workstation I would honestly go with the batch script (even if I had to learn it first), or a simple c# console project, but thats my humble oppinion. There are however many ways to do this with php as well: http://stackoverflow.com/a/8030848/752527 – Hanlet Escaño Aug 14 '13 at 16:03
  • I've read several approaches like the one you linked, however, that example is ran on a linux server, and the person doing the question seems to have the same issue with the output I'm talking about. The solution provided just verifies a flag "$status" but does not get an output per se. Thanks for the comment tho – Julian Aug 14 '13 at 16:08

1 Answers1

0

Given a text list in .ini format like this:

servers.ini

[servers]
hostnames[]='host1'
hostnames[]='host2'
hostnames[]='host3'
hostnames[]='hostN'

I suggest writing code like this, leveraging the PHP built-in function gethostbyname() :

<?php
// Parse without sections
$servers_array = parse_ini_file("servers.ini");

$results = array();

foreach ($servers_array['hostnames'] as $hostname){
    $ip = gethostbyname($hostname);
    $results[$hostname] = $ip;
}

print_r($results);
bubba
  • 3,839
  • 21
  • 25