staci trochu chciet ...
<?php
# /-----------------------------------\
# | Written By: Ian Redden |
# | Date: December 21st, 2005 |
# \-----------------------------------/
#
# $host = ip address of mikrotik box
# $community = ro/rw community name
#
$host = "192.168.1.1";
$community = "public";
#
# Purpose:
# --------
# Not sure really. Wrote it as a test to work with MRTG/RRDTOOL to
# graph wireless signal levels of connected clients.
#
# ENJOY!
#
# Requirements:
# -------------
# PHP 4 with SNMP
#
# Example Output:
# ---------------
# 00:01:F4:EC:8C:DC,-48 dBm,1135220890,omni-wireless
# 00:02:6F:39:63:89,-23 dBm,1135220890,omni-wireless
# 00:02:6F:39:65:14,-64 dBm,1135220890,home-link
# 00:02:6F:39:65:27,-59 dBm,1135220890,omni-wireless
# 00:02:6F:39:66:A1,-30 dBm,1135220890,omni-wireless
# 00:02:6F:39:68:98,-60 dBm,1135220890,omni-wireless
# 00:04:5A:2D:B2:7E,-59 dBm,1135220890,omni-wireless
# 00:06:11:00:01:90,-27 dBm,1135220890,omni-wireless
# 00:06:11:00:07:B3,-31 dBm,1135220890,omni-wireless
# 00:06:11:00:07:B4,-50 dBm,1135220890,omni-wireless
# 00:06:11:00:0F:0A,-48 dBm,1135220890,omni-wireless
# 00:06:11:00:16:F7,-30 dBm,1135220890,omni-wireless
# 00:06:11:00:17:05,-44 dBm,1135220890,omni-wireless
# 00:06:11:00:18:89,-55 dBm,1135220890,omni-wireless
# 00:06:11:00:19:48,-44 dBm,1135220890,omni-wireless
# 00:06:11:01:00:72,-50 dBm,1135220890,omni-wireless
# 00:06:11:01:00:8C,-32 dBm,1135220890,omni-wireless
# 00:06:11:01:04:35,-51 dBm,1135220890,omni-wireless
# 00:06:11:01:04:85,-46 dBm,1135220890,omni-wireless
# 00:06:11:20:11:DA,-66 dBm,1135220890,omni-wireless
# 00:06:11:20:14:38,-42 dBm,1135220890,omni-wireless
# 00:06:11:20:14:45,-49 dBm,1135220890,omni-wireless
# 00:06:11:20:16:75,-67 dBm,1135220890,omni-wireless
# 00:0C:41:3A:3A:04,-41 dBm,1135220890,omni-wireless
# 00:0C:41:3A:3E:9C,-48 dBm,1135220890,omni-wireless
# 00:12:17:0D:A5:9B,-62 dBm,1135220890,omni-wireless
# 00:12:17:0F:01:4D,-49 dBm,1135220890,omni-wireless
# 00:12:17:CD:BA:47,-45 dBm,1135220890,omni-wireless
# 00:13:10:3D:5B:6E,-55 dBm,1135220890,omni-wireless
# 00:50:18:02:70:89,-29 dBm,1135220890,omni-wireless
# 00:60:B3:19:43:E1,-28 dBm,1135220890,omni-wireless
#
function fsnmpget($host, $community, $mib) {
$str = snmpget($host, $community, $mib);
$str = str_replace("STRING: ", "", $str);
$str = str_replace("GAUGE32: ", "", $str);
$str = str_replace("COUNTER32: ", "", $str);
$str = str_replace("HEX: ", "", $str);
$str = str_replace("INTEGER: ", "", $str);
$str = str_replace("\"", "", $str);
return $str;
}
function fsnmpwalk($host, $community, $mib) {
$str = snmpwalk($host, $community, $mib);
$str = str_replace("STRING: ", "", $str);
$str = str_replace("COUNTER32: ", "", $str);
$str = str_replace("GAUGE32: ", "", $str);
$str = str_replace("INTEGER: ", "", $str);
$str = str_replace("HEX: ", "", $str);
$str = str_replace("\"", "", $str);
return $str;
}
function fsnmpwalkoid($host, $community, $mib) {
$str = snmpwalkoid($host, $community, $mib);
$str = str_replace("STRING: ", "", $str);
$str = str_replace("COUNTER32: ", "", $str);
$str = str_replace("GAUGE32: ", "", $str);
$str = str_replace("INTEGER: ", "", $str);
$str = str_replace("HEX: ", "", $str);
$str = str_replace("\"", "", $str);
return $str;
}
$host = $GLOBALS["host"];
$community = $GLOBALS["community"];
$time = date("U");
#
# Get Description, Location and Name from AP
$systemDescription = fsnmpget($host, $community, "system.sysDescr.0");
$systemLocation = fsnmpget($host, $community, "system.sysLocation.0");
$systemName = fsnmpget($host, $community, "system.sysName.0");
$strength = fsnmpwalkoid($host, $community, ".1.3.6.1.4.1.14988.1.1.1.2.1.3");
$interfaces = fsnmpwalkoid($host, $community, ".1.3.6.1.2.1.2.2.1.2");
array_walk($strength, 'signal_strength');
function dec2hex($value) {
return str_replace(" ", "0", sprintf("%2X", $value));
}
function format_mac($key, $num = 3) {
$mac_parse = str_replace("SNMPv2-SMI::enterprises.14988.1.1.1.2.1.$num.", "", $key);
$mac_decimal = substr($mac_parse, 0, strlen($mac_parse)-2);
list($first, $second, $third, $fourth, $fifth, $sixth) = split("[:.-]", $mac_decimal);
return dec2hex($first).":".dec2hex($second).":".dec2hex($third).":".dec2hex($fourth).":".dec2hex($fifth).":".dec2hex($sixth);
}
function get_interface($key, $num = 3) {
$mac_parse = str_replace("SNMPv2-SMI::enterprises.14988.1.1.1.2.1.$num.", "", $key);
$mac_decimal = substr($mac_parse, 0, strlen($mac_parse));
list($first, $second, $third, $fourth, $fifth, $sixth, $int) = split("[:.-]", $mac_decimal);
return "$int";
}
function flipmac($mac) {
return hexdec(substr($mac, 0, 2)).".".hexdec(substr($mac, 2, 2)).".".hexdec(substr($mac, 4, 2)).".".hexdec(substr($mac, 6, 2)).".".hexdec(substr($mac, 8, 2)).".".hexdec(substr($mac, 10, 2));
}
function signal_strength($value, $key) {
global $host, $community, $time, $interfaces;
$mac = format_mac($key);
$interfacenum = get_interface($key);
$interfacename = $interfaces["IF-MIB::ifDescr.".$interfacenum];
echo $interfaces[0];
$signal = $value." dBm";
$macfind = str_replace(":", "", $mac);
?>
<? echo $mac; ?>,<? echo $signal; ?>,<? echo $time; ?>,<? echo $interfacename; ?>
<?
}
?>