forked from willdurand/nmap
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,325 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{yml,yaml}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,36 +10,37 @@ | |
|
||
namespace Nmap; | ||
|
||
/** | ||
* @author Dany Maillard <[email protected]> | ||
*/ | ||
class Address | ||
{ | ||
|
||
const TYPE_IPV4 = 'ipv4'; | ||
|
||
const TYPE_MAC = 'mac'; | ||
|
||
private $address; | ||
private $type; | ||
private $vendor; | ||
private string $address; | ||
|
||
private string $type; | ||
|
||
private string $vendor; | ||
|
||
public function __construct(string $address, string $type = self::TYPE_IPV4, $vendor = '') | ||
public function __construct(string $address, string $type = self::TYPE_IPV4, string $vendor = '') | ||
{ | ||
$this->address = $address; | ||
$this->type = $type; | ||
$this->vendor = $vendor; | ||
} | ||
|
||
public function getAddress() : string | ||
public function getAddress(): string | ||
{ | ||
return $this->address; | ||
} | ||
|
||
public function getType() : string | ||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function getVendor() : string | ||
public function getVendor(): string | ||
{ | ||
return $this->vendor; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,35 +10,33 @@ | |
|
||
namespace Nmap; | ||
|
||
/** | ||
* @author William Durand <[email protected]> | ||
*/ | ||
class Host | ||
{ | ||
const STATE_UP = 'up'; | ||
|
||
const STATE_UP = 'up'; | ||
|
||
const STATE_DOWN = 'down'; | ||
|
||
private $addresses; | ||
private array $addresses; | ||
|
||
private $state; | ||
private string $state; | ||
|
||
private $hostnames; | ||
private array $hostnames; | ||
|
||
private $ports; | ||
private array $ports; | ||
|
||
private $scripts = []; | ||
private array $scripts = []; | ||
|
||
private $os; | ||
private ?string $os = null; | ||
|
||
private $os_accuracy; | ||
private ?int $os_accuracy = null; | ||
|
||
public function __construct(array $addresses, string $state, array $hostnames = array(), array $ports = array()) | ||
public function __construct(array $addresses, string $state, array $hostnames = [], array $ports = []) | ||
{ | ||
$this->addresses = $addresses; | ||
$this->state = $state; | ||
$this->state = $state; | ||
$this->hostnames = $hostnames; | ||
$this->ports = $ports; | ||
$this->ports = $ports; | ||
} | ||
|
||
public function setScripts(array $scripts) | ||
|
@@ -56,30 +54,18 @@ public function setOsAccuracy(int $accuracy) | |
$this->os_accuracy = $accuracy; | ||
} | ||
|
||
/** | ||
* @return string | ||
* | ||
* @deprecated The Host::getAddress() method is deprecated since 0.4 version. Use Host::getIpv4Addresses() instead. | ||
*/ | ||
public function getAddress() : string | ||
{ | ||
return current($this->getIpv4Addresses())->getAddress(); | ||
} | ||
|
||
/** | ||
* @return Address[] | ||
*/ | ||
public function getAddresses() : array | ||
public function getAddresses(): array | ||
{ | ||
return $this->addresses; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* | ||
* @return Address[] | ||
*/ | ||
private function getAddressesByType(string $type) : array | ||
private function getAddressesByType(string $type): array | ||
{ | ||
return array_filter($this->addresses, function (Address $address) use ($type) { | ||
return $address->getType() === $type; | ||
|
@@ -89,71 +75,65 @@ private function getAddressesByType(string $type) : array | |
/** | ||
* @return Address[] | ||
*/ | ||
public function getIpv4Addresses() : array | ||
public function getIpv4Addresses(): array | ||
{ | ||
return $this->getAddressesByType(Address::TYPE_IPV4); | ||
} | ||
|
||
/** | ||
* @return Address[] | ||
*/ | ||
public function getMacAddresses() : array | ||
public function getMacAddresses(): array | ||
{ | ||
return $this->getAddressesByType(Address::TYPE_MAC); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getState() : string | ||
public function getState(): string | ||
{ | ||
return $this->state; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOs() : ?string | ||
public function getOs(): ?string | ||
{ | ||
return $this->os; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getOsAccuracy() : ?int | ||
public function getOsAccuracy(): ?int | ||
{ | ||
return $this->os_accuracy; | ||
} | ||
|
||
/** | ||
* @return Hostname[] | ||
*/ | ||
public function getHostnames() : array | ||
public function getHostnames(): array | ||
{ | ||
return $this->hostnames; | ||
} | ||
|
||
/** | ||
* @return Script[] | ||
*/ | ||
public function getScripts() : array | ||
public function getScripts(): array | ||
{ | ||
return $this->scripts; | ||
} | ||
|
||
/** | ||
* @return Port[] | ||
*/ | ||
public function getPorts() : array | ||
public function getPorts(): array | ||
{ | ||
return $this->ports; | ||
} | ||
|
||
/** | ||
* @return Port[] | ||
*/ | ||
public function getOpenPorts() : array | ||
public function getOpenPorts(): array | ||
{ | ||
return array_filter($this->ports, function ($port) { | ||
return $port->isOpen(); | ||
|
@@ -163,10 +143,8 @@ public function getOpenPorts() : array | |
/** | ||
* @return Port[] | ||
*/ | ||
public function getClosedPorts() : array | ||
public function getClosedPorts(): array | ||
{ | ||
return array_filter($this->ports, function ($port) { | ||
return $port->isClosed(); | ||
}); | ||
return array_filter($this->ports, fn ($port) => $port->isClosed()); | ||
} | ||
} |
Oops, something went wrong.