Code backup
This commit is contained in:
2026-05-10 16:59:01 +02:00
commit 368d6fafea
796 changed files with 315310 additions and 0 deletions
+142
View File
@@ -0,0 +1,142 @@
using System;
using System.Net;
using System.Linq;
using System.Collections;
using System.Runtime.InteropServices;
namespace devlist
{
public class IPEnumeration: IEnumerable
{
private string startAddress;
private string endAddress;
internal static Int64 AddressToInt(IPAddress addr)
{
byte[] addressBits = addr.GetAddressBytes();
Int64 retval = 0;
for (int i = 0; i < addressBits.Length; i++)
{
retval = (retval << 8) + (int)addressBits[i];
}
return retval;
}
internal static Int64 AddressToInt(string addr)
{
return AddressToInt(IPAddress.Parse(addr));
}
internal static IPAddress IntToAddress(Int64 addr)
{
return IPAddress.Parse(addr.ToString());
}
public IPEnumeration(string startAddress, string endAddress)
{
this.startAddress = startAddress;
this.endAddress = endAddress;
}
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator) GetEnumerator();
}
public IPEnumerator GetEnumerator()
{
return new IPEnumerator(startAddress, endAddress);
}
}
public class IPEnumerator: IEnumerator
{
private string startAddress;
private string endAddress;
private Int64 currentIP;
private Int64 endIP;
public IPEnumerator(string startAddress, string endAddress)
{
this.startAddress = startAddress;
this.endAddress = endAddress;
currentIP = IPEnumeration.AddressToInt(startAddress);
endIP = IPEnumeration.AddressToInt(endAddress);
}
public bool MoveNext()
{
currentIP++;
return (currentIP <= endIP);
}
public void Reset()
{
currentIP = IPEnumeration.AddressToInt(startAddress);
}
object IEnumerator.Current
{
get
{
return Current;
}
}
public IPAddress Current
{
get
{
try
{
return IPEnumeration.IntToAddress(currentIP);
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
}
public static class IPHelper
{
[DllImport("iphlpapi.dll", ExactSpelling=true)]
public static extern int SendARP( int DestIP, int SrcIP, byte[] pMacAddr, ref uint PhyAddrLen);
public static string getMAC(IPAddress address)
{
int intAddress = BitConverter.ToInt32(address.GetAddressBytes(), 0);
byte[] macAddr = new byte[6];
uint macAddrLen = (uint) macAddr.Length;
if (SendARP(intAddress, 0, macAddr, ref macAddrLen) != 0)
return "(NO ARP result)";
string[] str = new string[(int)macAddrLen];
for (int i = 0; i < macAddrLen; i++)
str[i] = macAddr[i].ToString("x2");
return string.Join(":", str);
}
}
class Program
{
public static void Main(string[] args)
{
foreach(IPAddress addr in new IPEnumeration("172.25.216.10","172.25.216.20"))
{
Console.WriteLine("{0}\t\t{1}",addr.ToString(), IPHelper.getMAC(addr));
}
Console.ReadKey(true);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
TextToBeWritten = "Pinging 172.16.94.95... \r\n";
Ping ping = new Ping();
PingReply pingReply = ping.Send("172.16.94.95");
if (pingReply.Status == IPStatus.Success)
{
//Machine is alive
TextToBeWritten += "Success!";
}
else
TextToBeWritten += "Error!";
+37
View File
@@ -0,0 +1,37 @@
TextToBeWritten = "<div>Pinging... </div>";
string ipBase = "172.16.94.";
for (int i = 1; i < 100; i++)
{
string ip = ipBase + i.ToString();
Ping p = new Ping();
var pingReply = p.Send(ip, 100);
if (pingReply.Status != IPStatus.Success)
TextToBeWritten += "<div><div class=\"host-offline\">Offline</div>" + ip + "</div>";
else
{
//Machine is alive
TextToBeWritten += "<div><div class=\"host-online\">Online</div>" + ip + "</div>";
IPAddress hostIPAddress = IPAddress.Parse(ip);
TextToBeWritten += "<div>";
try
{
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
IPAddress[] address = hostInfo.AddressList;
String[] alias = hostInfo.Aliases;
TextToBeWritten += "Host: " + hostInfo.HostName;
}
catch (Exception e)
{
TextToBeWritten += "DNS Resolution Error: " + e.Message;
}
TextToBeWritten += "</div>";
}
}
+116
View File
@@ -0,0 +1,116 @@
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(" ", "&emsp;&emsp;&emsp;");
line = line.Replace(" ", "&emsp;&emsp;");
line = line.Replace(" ", "&emsp;");
line = line.Replace(" ", "&emsp;");
line = line.Replace(" ", "&emsp;");
line = line.Replace(" ", "&emsp;&emsp;");
line = line.Replace(" ", "&emsp;");
TextToBeWritten += "User Actualy Logged:<br>" + line;
}
catch (Exception e)
{
TextToBeWritten += "DNS Resolution Error: " + e.Message + "<br>";
}
TextToBeWritten += "<br></div>";
}
}
}
}
}
+117
View File
@@ -0,0 +1,117 @@
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... <br></div>";
//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 += "<hr class=\"solid\">" + "<div>" + "<span class=\"host-offline\">● </span>Offline " + ip + "<br>Host: Disconnesso" + "<br><br></div>";
else
{
//Machine is alive
TextToBeWritten += "<hr class=\"solid\">" + "<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(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
line = line.Replace(" ", "&ensp;&ensp;");
TextToBeWritten += "User Actualy Logged:<br>" + line;
}
catch (Exception e)
{
TextToBeWritten += "DNS Resolution Error: " + e.Message;
}
TextToBeWritten += "</div>";
}
}
}
}
}
+38
View File
@@ -0,0 +1,38 @@
string name = "Franco".ToUpper();
string surname = "Di Sorte".ToUpper().Replace(" ","");
List<string> rawAlias = new List<string>();
var range = string.Empty;
if (name.Length > surname.Length) { range = surname; } else { range = name; }
for (int i = 1;
i < 3;
i++)
{
if (i != 1)
{
rawAlias.Add($"{name[0..i]}{surname[0..i]}");
rawAlias.Add($"{name[0..i]}{surname[0]}");
rawAlias.Add($"{name[0]}{surname[0..i]}");
continue;
}
rawAlias.Add($"{name[0..i]}{surname[0..i]}");
}
rawAlias.Sort();
var alias = rawAlias.OrderBy(x => x.Length);
var existAlias = new List<string>()
{
{""}
};
foreach (var a in alias)
{
if(!existAlias.Contains(a))
Console.WriteLine(a);
}