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 = "
Pinging...
"; //ip da teneresott'occhio 172.16.94.1-254 string ipBase = "172.16.94."; for (int i = 30; i < 40; i++) { string ip = ipBase + i.ToString(); Ping p = new Ping(); var pingReply = p.Send(ip, 50); if (pingReply.Status != IPStatus.Success) TextToBeWritten += "
" + "
" + "Offline " + ip + "
Host: Disconnesso" + "

"; else { //Machine is alive TextToBeWritten += "
" + "
" + "Online " + ip + "
"; IPAddress hostIPAddress = IPAddress.Parse(ip); TextToBeWritten += "
"; //DNS hostbyaddress try { IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress); IPAddress[] address = hostInfo.AddressList; String[] alias = hostInfo.Aliases; TextToBeWritten += "Host: " + hostInfo.HostName + "
"; 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", "
" + 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:
" + line; } catch (Exception e) { TextToBeWritten += "DNS Resolution Error: " + e.Message; } TextToBeWritten += "
"; } } } } }