Debian Codegraph @

cdprs/cdprs.php

raw
1 <?
2 /*
3 ** cdprs.php - Sample PHP script to collect cdpr data to a file
4 **
5 ** Copyright (c) 2002-2008 MonkeyMental.com
6 **
7 ** This program will show you which Cisco device your machine is
8 ** connected to based on CDP packets received.
9 **
10 ** This program is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License
12 ** as published by the Free Software Foundation; either version 2
13 ** of the License, or (at your option) any later version.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24 header("Content-type: plain/text");
25
26 $switch = $_GET["switch_ip"];
27 $switch6 = $_GET["switch_ip6"];
28 $port = $_GET["port"];
29 $host = $_GET["host"];
30 $loc = $_GET["loc"];
31
32 if(!$fh = fopen("/tmp/cdprs.txt", "a+b"))
33 {
34 printf("Error opening file\n");
35 exit();
36 }
37
38 $cdprs = sprintf("Switch: %s/%s Port: $port Host: $host Location: $loc\n",
39 $switch, $switch6, $port, $host, $loc);
40
41 if(!fwrite($fh, $cdprs))
42 {
43 printf("Error writing data to file\n");
44 fclose($fh);
45 exit();
46 }
47 else
48 {
49 print("Update Sucessful\n");
50 }
51
52 ?>