need help determinig type of server

Discussion in 'PHP' started by Katanius, Apr 14, 2007.

  1. #1
    hi,

    Im looking for a way to determine what kind of server a host is.

    Ive writen a script to scan ip ranges an find live hosts but i need a way to find out if the host is a web server, mail server, dns etc.

    how can i do this? im new at this and im realy stuck ... plz help

    even a way to determine just one type of host (e.g. web server) would be highly apreciated

    thank you
     
    Katanius, Apr 14, 2007 IP
  2. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Katanius what the information you are requesting I think this is the best lik you will get help from here -> http://in2.php.net/reserved.variables.

    Any other help you need fell free to ask :)
     
    Subikar, Apr 15, 2007 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    One host can be both a web server, mail server, and dns server, etc. Different services use different port numbers. Are you talking about port scanner?
     
    wmtips, Apr 15, 2007 IP
  4. Katanius

    Katanius Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you very much Subikar :)

    following the link i found the getservbyname() and getservbyport() functions, is it posible to use them to identify the server type? ill try it allthough i dont know exactly how this can be done.

    i guess it would be more something like a portsweeper,

    Basicly im using nslookup to see if an ip coresponds to a host. What im trying to do is make a script that outputs a txt file that contains something like this:

    <<IP:62.169.194.16 Host: www.something.gr is a WEB_SERVER>>
    <<IP:62.169.194.17 Host: dns1.something.gr is a DNS>>
    e.t.c.

    Ive reached to the <<IP:62.169.194.16 Host: www.something.gr>> part my self but now im not realy shure how to go on. I can post the script if you need more details.

    thank you very much for answering :)
     
    Katanius, Apr 15, 2007 IP
  5. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    use dig, that way you can look for a specific records type, for instance mx records for smtp/pop/imap servers and ns records for domain name servers and a records for website / webserver, dig is a unix command, however I have seen classes on phpclasses that "claim" to achieve the same results, I never tested them though, just noted it was interesting that it could be done.
     
    krakjoe, Apr 16, 2007 IP
  7. Katanius

    Katanius Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Im running php on a windows platform so i cant use them, i also tryed the PEAR Net_DNS class but couldnt get it to work so i think i ll go with port scanning.

    Using the information i found i wrote the followin script which im going to later use in a loop:

    
    <?php
    
    $host='dns1.tellas.gr';
    $port=80;
    
    echo "$host.<br>";
    
      $service = getservbyport($port, "tcp");
      $result = @fsockopen($host, $port);
      stream_set_timeout($result, 1);
      fclose($result);
    
      echo "getservbyport result:.<br>";
      echo "Port: $port is commonly used for: $service";
      
      if($result)
    	{
    		echo " OPEN";
    	}
    	else
    	{
    		echo " CLOSED";
    	}
    ?>
    
    Code (markup):
    the server used is obviusly a dns, getservbyport returns http as a service allthough the port is closed. what does this mean? have i done something wrong?
    Or should i disregard the getservbyport function and just identify type of server by port being open or closed?
     
    Katanius, Apr 16, 2007 IP
  8. Katanius

    Katanius Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I eventualy used fsockopen to listen to ports 80, 20, 110, 53 but it takes aproximatly 30sec to scan each port that isnt open. This is like 2min per IP, if i would scan 500 ips it would take like half a day!:(

    Isnt port scanning supposed to be fast?
     
    Katanius, Apr 16, 2007 IP
  9. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #9
    RTM. fsockopen has optional timeout parameter:
     
    wmtips, Apr 17, 2007 IP
  10. Katanius

    Katanius Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    thank you very much :) now it seems to work fine :)
     
    Katanius, Apr 17, 2007 IP