mirror of
https://github.com/hak5/nano-tetra-modules.git
synced 2025-10-29 16:58:09 +00:00
Add modules to repository
This commit is contained in:
45
MACInfo/api/module.php
Normal file
45
MACInfo/api/module.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php namespace pineapple;
|
||||
|
||||
|
||||
/* The class name must be the name of your module, without spaces. */
|
||||
/* It must also extend the "Module" class. This gives your module access to API functions */
|
||||
class MACInfo extends Module
|
||||
{
|
||||
public function route()
|
||||
{
|
||||
switch ($this->request->action) {
|
||||
case 'getMACInfo':
|
||||
$this->getMACInfo($this->request->moduleMAC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function getMACInfo($mac)
|
||||
{
|
||||
if($this->IsValidMAC($mac)){
|
||||
$url = "http://macvendors.co/api/" . $mac . "/JSON";
|
||||
$retJSON = file_get_contents($url);
|
||||
if($retJSON != false){
|
||||
$mInfo = json_decode($retJSON);
|
||||
if(isset($mInfo) && isset($mInfo->result) && $mInfo->result->error != ""){
|
||||
$this->response = array("success" => false, "error" => $mInfo->result->error);
|
||||
}
|
||||
else{
|
||||
$this->response = array("success" => true,
|
||||
"company" => $mInfo->result->company,
|
||||
"macprefix" => $mInfo->result->mac_prefix,
|
||||
"address" => $mInfo->result->address,
|
||||
"country" => $mInfo->result->country,
|
||||
"type" => $mInfo->result->type
|
||||
);
|
||||
}
|
||||
}
|
||||
else{ $this->response = array("success" => false, "error" => "Error reading contents from: " . $url); }
|
||||
}
|
||||
else{ $this->response = array("success" => false, "error" => "Invalid MAC Address format"); }
|
||||
}
|
||||
private function IsValidMAC($mac) {
|
||||
$pregResult = preg_match('/([a-fA-F0-9]{2}[:|\-]?){6}/', $mac);
|
||||
return ($pregResult != 0 && $pregResult != NULL);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user