368d6fafea
Code backup
117 lines
3.9 KiB
C#
117 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.NetworkInformation;
|
|
using System.Net.Sockets;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Localization;
|
|
using webapp_shared;
|
|
|
|
namespace webapp_local.Pages.InfoTech
|
|
{
|
|
public class ServerLoginsModel : _LayoutModel
|
|
{
|
|
|
|
|
|
public string TextToBeWritten { get; set; }
|
|
public ServerLoginsModel(IStringLocalizer<_LayoutModel> _localizer, IConfiguration _config) : base(_localizer, _config)
|
|
{
|
|
}
|
|
|
|
public override void OnGet()
|
|
{
|
|
base.OnGet();
|
|
|
|
if (!Permissions.CanViewVisitorsRegister)
|
|
{
|
|
// Redirect a 404
|
|
Response.Redirect("/Error");
|
|
}
|
|
|
|
TextToBeWritten = "<div>Pinging... </div>";
|
|
|
|
//ip da teneresott'occhio 172.16.94.1-254
|
|
string ipBase = "172.16.91.";
|
|
for (int i = 1; i < 254; i++)
|
|
{
|
|
string ip = ipBase + i.ToString();
|
|
|
|
Ping p = new Ping();
|
|
var pingReply = p.Send(ip, 50);
|
|
|
|
|
|
|
|
if (pingReply.Status != IPStatus.Success)
|
|
TextToBeWritten += "<div>" + "<span class=\"host-offline\">● </span>Offline " + ip + "<br>Host: Disconnesso" + "<br></div>";
|
|
else
|
|
{
|
|
//Machine is alive
|
|
TextToBeWritten += "<div>" + "<span class=\"host-online\">● </span>Online " + ip + "</div>";
|
|
|
|
IPAddress hostIPAddress = IPAddress.Parse(ip);
|
|
TextToBeWritten += "<div>";
|
|
|
|
//DNS hostbyaddress
|
|
try
|
|
{
|
|
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
|
|
IPAddress[] address = hostInfo.AddressList;
|
|
String[] alias = hostInfo.Aliases;
|
|
|
|
TextToBeWritten += "Host: " + hostInfo.HostName + "<br>";
|
|
|
|
|
|
String CmdText = @"/c quser /server:" + ip;
|
|
|
|
Process proc = new Process
|
|
{
|
|
StartInfo = new ProcessStartInfo
|
|
{
|
|
FileName = "cmd.exe",
|
|
Arguments = CmdText,
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true,
|
|
CreateNoWindow = true
|
|
}
|
|
};
|
|
|
|
proc.Start();
|
|
String line = proc.StandardOutput.ReadToEnd();
|
|
|
|
line = line.Replace("\r\n", "<br>" + System.Environment.NewLine);
|
|
|
|
line = line.Replace("NOMEUTENTE", "UTENTE");
|
|
line = line.Replace("NOMESESSIONE", "SESSIONE");
|
|
|
|
line = line.Replace(" ", "   ");
|
|
line = line.Replace(" ", "  ");
|
|
line = line.Replace(" ", " ");
|
|
line = line.Replace(" ", " ");
|
|
line = line.Replace(" ", " ");
|
|
line = line.Replace(" ", "  ");
|
|
line = line.Replace(" ", " ");
|
|
|
|
TextToBeWritten += "User Actualy Logged:<br>" + line;
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
TextToBeWritten += "DNS Resolution Error: " + e.Message + "<br>";
|
|
}
|
|
|
|
TextToBeWritten += "<br></div>";
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|