Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (81 loc) · 3.47 KB
/
Copy pathProgram.cs
File metadata and controls
85 lines (81 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Создано в SharpDevelop.
* Дата: 13.08.2019
*
* Для изменения этого шаблона используйте меню "Инструменты | Параметры | Кодирование | Стандартные заголовки".
*/
using System;
namespace ShowIPtoConsole
{
class Program
{
public static string PrgTitle { get { return "ShowIP.exe"; } }
static string DetectOption(string key)
{
switch (key)
{
case ("-h"): case ("--help"): { return "help"; }
case ("-t"): case ("--txt"): { return "export txt"; }
case ("--html"): { return "export html"; }
case ("-f"): case ("--fb2"): { return "export fb2"; }
default: { return "undefined"; }
}
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <param name="ip"></param>
/// <returns>sukcessful or fail operation</returns>
static bool CompleteCommand(string command, string ip)
{
if (command == "undefined") return false;
if (command == "help")
{
Console.WriteLine("usage:");
Console.WriteLine(PrgTitle);
Console.WriteLine("\tShow ext. IP in this cmd");
Console.WriteLine(PrgTitle + " -h || " + PrgTitle + " --help");
Console.WriteLine("\tShow this help message");
Console.WriteLine(PrgTitle + " -t || " + PrgTitle + " --txt");
Console.WriteLine("\texport to ExternalIP.txt ");
Console.WriteLine(PrgTitle + " -f || " + PrgTitle + " --fb2");
Console.WriteLine("\tKaptain Obvious");
Console.WriteLine(PrgTitle + " --html");
Console.WriteLine("\tKaptain Obvious");
return true;
}
if (command.Contains("export"))
{
if (ip == "undefined") return false;//FIXME a.b.c.d ip4 format
var cse = CustomFileIO.SupportedExtensions.txt;
switch (command.Split(' ')[1])
{
case ("txt"): cse = CustomFileIO.SupportedExtensions.txt; break;
case ("html"): cse = CustomFileIO.SupportedExtensions.html; break;
case ("fb2"): cse = CustomFileIO.SupportedExtensions.fb2; break;
}
CustomFileIO.BrutforceWriteFile("ExternalIP", ip, cse);
return true;
}
//I prevent in 1th line of function, that this line dont be execute
throw new NotImplementedException();
}
public static void Main(string[] args)
{
if (args.Length > 1)
{
Console.WriteLine("too many arguments!\nSee --help (-h)");
return;
}
string publicIp = "My public IP Addres is: " + (new System.Net.WebClient()).DownloadString("https://api.ipify.org");
if (args.Length == 0)
{
Console.WriteLine(publicIp);
System.Threading.Thread.Sleep(5 * 1000);// because user can click for launch program
}
else
if (!CompleteCommand(DetectOption(args[0]), publicIp))
Console.WriteLine("runtime fail.\nSee --help");
}
}
}