using Microsoft.AspNetCore.Mvc; using Lextm.SharpSnmpLib; using Lextm.SharpSnmpLib.Messaging; using System.Net; using CartriX.Api.Models; namespace CartriX.Api.Controllers { [ApiController] [Route("api/Printer")] public class PrinterController : ControllerBase { private readonly AppDbContext _context; public PrinterController(AppDbContext context) { _context = context; } [HttpGet("getPages/{id}")] public ActionResult GetPages(int id) { Printer printer = _context.Printers.Find(id)!; if (printer == null) { return NotFound(); } var endpoint = new IPEndPoint(IPAddress.Parse(printer!.IpAddress!), 161); // community string (как "пароль" в SNMP v2c) var community = new OctetString("public"); // OID sysName.0 var oid = new ObjectIdentifier(printer.PrinterUsedPagesOID!); var result = Messenger.Get( VersionCode.V2, endpoint, community, new List { new Variable(oid) }, timeout: 2000 ); return Ok($"{result[0].Data}"); } } }