mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 04:20:55 +00:00
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
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);
|
|
var community = new OctetString("public");
|
|
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}");
|
|
}
|
|
//[HttpPost]
|
|
//public IActionResult AddPrinter([FromBody] CreateAddPrinterRequest PrinterDto)
|
|
//{
|
|
|
|
// }
|
|
}
|
|
} |