Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*use all System here*/
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- /*
- * using System.Text;
- * using System.Collections.Generic;
- * using System.Linq;
- */
- using System.Net;
- namespace Serco.Main
- {
- class Program
- {
- static void Main(string[] args)
- {
- show_main_menu(true);
- string option = show_main_menu();
- switch (option)
- {
- case "1":
- FindHostByAssetTag();
- break;
- }
- }
- static string show_main_menu(bool header = false)
- {
- if (header == true)
- {
- Console.Clear();
- Console.Write("Network Toolbox (V1) - Serco ICT Team - Developed by Robert Pitt\n\n");
- return "";
- }
- //Show the menu options
- Console.WriteLine("1) Find Host via Asset Tag");
- Console.WriteLine("To exit type 'exit' or 'x'");
- Console.WriteLine("\n\n");
- Console.Write("Please enter an option: ");
- string o = Console.ReadLine().ToString();
- return o;
- }
- /*
- * methods for each function!
- */
- static void FindHostByAssetTag(string error = "")
- {
- show_main_menu(true);
- Console.WriteLine("Asset Tag Searcher\n");
- if (error != "")
- {
- Console.WriteLine("Error: {0}\n",error);
- }
- Console.Write("Enter Asset Tag or * for all: ");
- string assetTag = Console.ReadLine().ToString();
- Regex AssetMatch = new Regex("[0-9]{6}|[*]{1}");
- if (AssetMatch.Match(assetTag).Success == false)
- {
- FindHostByAssetTag("Asset tag failed validation, please use exactly six digits");
- return;
- }
- /*lests start the search*/
- string localH = Dns.GetHostName();
- //Console.WriteLine("Current Host:" + localH);
- Console.WriteLine("Searching...");
- /*
- * DNS Searching Now
- */
- IPHostEntry localHostname = Dns.GetHostEntry(Dns.GetHostName());
- if (localHostname.AddressList.Length == 0)
- {
- FindHostByAssetTag("unable to detect any hosts at all. make sure a connection is active");
- return;
- }
- int count = 0;
- Dictionary<string, IPAddress> storage = new Dictionary<string, IPAddress>();
- foreach (IPAddress ip in localHostname.AddressList)
- {
- IPHostEntry Address = Dns.GetHostEntry(ip);
- string current_host = Address.HostName.ToString();
- if (assetTag == "*" || current_host.IndexOf(assetTag) > 0)
- {
- count++;
- storage.Add(count.ToString(),ip);//Store as string
- Console.WriteLine("("+count+")\t" + Address.HostName.ToString());
- }
- }
- if (count == 0)
- {
- FindHostByAssetTag("Unable to find any hosts matching (" + assetTag + ")");
- return;
- }
- //Show the menu select menu for the selected asset tag
- Console.WriteLine("Please select an ID for options: ");
- string selected = Console.ReadLine();
- if (Int32.Parse(selected) > 0 && storage.ContainsKey(selected))
- {
- if (storage.ContainsKey(selected))
- {
- show_main_menu(true);
- Console.WriteLine("options for item {0}", selected);
- string option = Console.ReadLine();
- }
- }
- else
- {
- Console.WriteLine("item could not be found!");
- Console.Read();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement