2012-08-21 16:55:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
App::uses('AppModel', 'Model');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Domain Name System related
|
|
|
|
*/
|
|
|
|
class Dns extends AppModel {
|
2012-09-18 15:30:32 +02:00
|
|
|
|
|
|
|
public $useTable = false;
|
2012-08-21 16:55:57 +02:00
|
|
|
|
2012-11-16 11:22:19 +01:00
|
|
|
/**
|
|
|
|
* Checks for a valid internet name
|
|
|
|
* Returns true if Name is an existing Domain Host Name, false otherwise
|
|
|
|
* TODO should be renamed
|
|
|
|
*
|
|
|
|
* @param unknown_type $nametotest The Domain Host Name to check for existence.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function testipaddress($nametotest) {
|
2012-09-18 15:30:32 +02:00
|
|
|
if (intval($nametotest) > 0) {
|
2012-08-21 16:55:57 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$ipaddress = $nametotest;
|
|
|
|
$ipaddress = gethostbyname($nametotest);
|
|
|
|
if ($ipaddress == $nametotest) {
|
|
|
|
return false;
|
2012-09-18 15:30:32 +02:00
|
|
|
} else {
|
2012-08-21 16:55:57 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-16 11:22:19 +01:00
|
|
|
/**
|
|
|
|
* Name to IP list,
|
|
|
|
* get all ip numbers given a certain domain or host $name.
|
|
|
|
*
|
|
|
|
* @param $name being a hostname
|
|
|
|
*
|
|
|
|
* @return array of ip numbers
|
|
|
|
*/
|
2012-11-19 14:49:38 +01:00
|
|
|
public function nametoipl($name = '') {
|
2014-02-05 15:01:26 +01:00
|
|
|
if ('true' == Configure::read('MISP.dns')) {
|
2012-11-19 14:49:38 +01:00
|
|
|
if (!$ips = gethostbynamel($name)) $ips = array();
|
|
|
|
} else {
|
|
|
|
$ips = array();
|
|
|
|
}
|
|
|
|
return $ips;
|
|
|
|
}
|
2012-08-21 16:55:57 +02:00
|
|
|
}
|