0

I have a problem with SNMP. I connect to SNMP with PHP using this code:

<?php
 $session = new SNMP(SNMP::VERSION_1, "xxx.xxx.xxx.xxx", "public");
 $fulltree = $session->walk(".");
 print_r($fulltree);
 echo "<br>";
 $session->close();
?>

The code works perfectly, it isn't the problem. The problem is can I have more IPs that I need connect with SNMP. I have a firewall (ZyWALL), and can have 4 printers. The problem occurs because I can set the 161 port only at one printer, and not at all.

enter image description here

How I can add the port 161 for all printers? Now i can see only one printers with the SNMP, but i need see all.

Zong
  • 6,160
  • 5
  • 32
  • 46
wolfphp22
  • 11
  • 1
  • 3

1 Answers1

0

option 1 is to pass the port explicitly if it's not the default 161

$sessionA = new SNMP(SNMP::VERSION_1, "192.168.1.204", "public"); //for port 161
$sessionB = new SNMP(SNMP::VERSION_1, "192.168.1.204:162", "public"); //for port 162

option 2, depending on your network set-up, is to assign different IPs to each printer so you can poll port 161 for each printer

you need to set up your firewall rules properly and according to the rules you access the printers.

so you if you have 4 printers all directly behind the firewall, each printer with it's own IP address, you map different incoming ports on the firewall to point to each respective printer's 161 port.

you would then open SNMP sessions like this

$sessionA = new SNMP(SNMP::VERSION_1, "public.firewall.ip.address:port1", "public"); 

for printer A, where port1 is the incoming port on the firewall that points to 161 on the printer

rinse and repeat for as many printers you have.

Alex Andrei
  • 7,315
  • 3
  • 28
  • 42
  • In this mode doesn't work. It work if for example i replace the port 5691 with the 161 at 192.168.1.204. After, if i call in new SNMP() the firewall i see the snmp for the printer can in local have 192.168.1.204 correctly. – wolfphp22 Jun 25 '15 at 09:29
  • what are the IPs for the printers? are they behind 192.168.1.204? also are from which IP are your running the php script from? – Alex Andrei Jun 25 '15 at 09:36
  • For example if i write ip.xxxxxx.com:5960 i see the printer. After in php i call the ip of the ip.xxxxxx.com host. In my firewall the port 5960 on ip 192.168.1.204 redirect to the 80 and i can see the printer. If i replace the port 5961 for the ip 192.168.1.204 with the 161, i can connect via SNMP correctly. The problem come because i have more ip can necessary have the port 161. – wolfphp22 Jun 25 '15 at 09:50
  • i just edited my answer, but it would help to understand the network topology and where you are calling the script from. if both 192.168.1.204 and 1.202 printers and 5550 and 5560 map to port 80 internally. then just map different ports like 6561 and 6562 respectively to port 161 internally. – Alex Andrei Jun 25 '15 at 10:13
  • This continue don't work. I see the printer only if i set the 161 in original port and mapped port. If for example i set 6678 in original port and in mapped port 161, don't work. Why? I'm going be crazy. Thank you for your help – wolfphp22 Jun 25 '15 at 10:57
  • original port is on public side, mapped port is on internal side. then call SNMP like this new SNMP(SNMP::VERSION_1, "public.firewall.ip.address:6678", "public"); it will follow the mapping to the internal IP address on port 161 – Alex Andrei Jun 25 '15 at 11:41
  • If for example the address where i see the printer is ip.xxxx.com:5560, what is the correct "public.firewall.ip.address:port" ?? Thank you again! – wolfphp22 Jun 25 '15 at 14:09