mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 12:30:55 +00:00
Сделал контроллер колторый обращается к принетеру по SNMP
This commit is contained in:
1 parent
69e4c977cb
commit
f702916cef
18 files changed
+1528
-37
No files matched your search
@@ -0,0 +1,46 @@
|
||||
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<Variable> { new Variable(oid) },
|
||||
timeout: 2000
|
||||
);
|
||||
|
||||
return Ok($"{result[0].Data}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user