-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
91 lines (74 loc) · 2.91 KB
/
Program.cs
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
86
87
88
89
90
91
using PcapDotNet.Core;
using PcapDotNet.Packets.IpV4;
namespace http_client
{
class Program
{
private static string DnsServerIp = "8.8.8.8";
private static void Main(string[] args)
{
HostnameResolver resolver;
HostnameResolver.ResolverStates resolverStatus;
IpV4Address DestIP;
MyHttpClient client;
PcapHelpers.InitModes pcapMode;
PcapHelpers.InitBehavior pcapBehavior = PcapHelpers.InitBehavior.Eager;
string inputAddr;
int provisionedDevId = -1;
if (args.Length == 0)
{
pcapMode = PcapHelpers.InitModes.User_Interaction;
inputAddr = GetDestinationFromUser();
}
else if (args.Length == 1){
pcapMode = PcapHelpers.InitModes.User_Interaction;
inputAddr = args[0];
}
else if (args.Length == 2){
pcapMode = PcapHelpers.InitModes.Provisioning;
provisionedDevId = Int32.Parse(args[0]);
inputAddr = args[1];
}
else{
return;
}
var Pcap = PcapHelpers.InitInterface(pcapMode, pcapBehavior, provisionedDevId);
//var Pcap = PcapHelpers.InitInterface(PcapHelpers.InitModes.Provisioning, PcapHelpers.InitBehavior.Eager, 1);
PrintDeviceAddresses(Pcap.addresses);
resolver = new HostnameResolver(Pcap.addresses, Pcap.device, DnsServerIp);
DestIP = resolver.GetIpFromInput(inputAddr, out resolverStatus);
PrintDestIP(DestIP);
if (resolverStatus == HostnameResolver.ResolverStates.RESOLVED){
PrintHostname(inputAddr);
}
Console.WriteLine("\n\n");
client = new MyHttpClient(Pcap.addresses, Pcap.device);
if (resolverStatus == HostnameResolver.ResolverStates.RESOLVED){
client.GetSync(DestIP, inputAddr);
}else{
client.GetSync(DestIP);
}
Console.ReadLine();
}
private static void PrintDeviceAddresses(MandatoryAddresses addrs)
{
Console.WriteLine("Source IP: " + addrs.SourceIP);
Console.WriteLine("Source MAC: " + addrs.SourceMAC);
Console.WriteLine("Destination MAC: " + addrs.DestMAC);
}
private static void PrintDestIP(IpV4Address addr)
{
Console.WriteLine("Destination IP: " + addr.ToString());
}
private static void PrintHostname(string host)
{
Console.WriteLine("Host: " + host);
}
private static String GetDestinationFromUser()
{
Console.WriteLine("Enter address(hostname/ip) to send a http get request.");
string input = Console.ReadLine()!;
return input;
}
}
}