/
Networking.cs
166 lines (145 loc) · 5.1 KB
/
Networking.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//----------------------------------------------------------------------------------------------
// <copyright file="Networking.cs" company="Microsoft Corporation">
// Licensed under the MIT License. See LICENSE.TXT in the project root license information.
// </copyright>
//----------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Threading.Tasks;
namespace Microsoft.Tools.WindowsDevicePortal
{
/// <content>
/// Wrappers for Networking methods.
/// </content>
public partial class DevicePortal
{
/// <summary>
/// API for getting IP config data.
/// </summary>
private static readonly string IpConfigApi = "api/networking/ipconfig";
/// <summary>
/// Gets the IP configuration data of the device.
/// </summary>
/// <returns>object containing details of the device's network configuration.</returns>
public async Task<IpConfiguration> GetIpConfig()
{
return await this.Get<IpConfiguration>(IpConfigApi);
}
#region Data contract
/// <summary>
/// DHCP object.
/// </summary>
[DataContract]
public class Dhcp
{
/// <summary>
/// Gets or sets the time at which the lease will expire, in ticks.
/// </summary>
[DataMember(Name = "LeaseExpires")]
public long LeaseExpiresRaw { get; set; }
/// <summary>
/// Gets or sets the time at which the lease was obtained, in ticks.
/// </summary>
[DataMember(Name = "LeaseObtained")]
public long LeaseObtainedRaw { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
[DataMember(Name = "Address")]
public IpAddressInfo Address { get; set; }
/// <summary>
/// Gets the lease expiration time.
/// </summary>
public DateTimeOffset LeaseExpires
{
get { return new DateTimeOffset(new DateTime(this.LeaseExpiresRaw)); }
}
/// <summary>
/// Gets the lease obtained time.
/// </summary>
public DateTimeOffset LeaseObtained
{
get { return new DateTimeOffset(new DateTime(this.LeaseObtainedRaw)); }
}
}
/// <summary>
/// IP Address info
/// </summary>
[DataContract]
public class IpAddressInfo
{
/// <summary>
/// Gets or sets the address
/// </summary>
[DataMember(Name = "IpAddress")]
public string Address { get; set; }
/// <summary>
/// Gets or sets the subnet mask
/// </summary>
[DataMember(Name = "Mask")]
public string SubnetMask { get; set; }
}
/// <summary>
/// IP Configuration object
/// </summary>
[DataContract]
public class IpConfiguration
{
/// <summary>
/// Gets or sets the list of networking adapters
/// </summary>
[DataMember(Name = "Adapters")]
public List<NetworkAdapterInfo> Adapters { get; set; }
}
/// <summary>
/// Networking adapter info
/// </summary>
[DataContract]
public class NetworkAdapterInfo
{
/// <summary>
/// Gets or sets the description
/// </summary>
[DataMember(Name = "Description")]
public string Description { get; set; }
/// <summary>
/// Gets or sets the hardware address
/// </summary>
[DataMember(Name = "HardwareAddress")]
public string MacAddress { get; set; }
/// <summary>
/// Gets or sets the index
/// </summary>
[DataMember(Name = "Index")]
public int Index { get; set; }
/// <summary>
/// Gets or sets the name
/// </summary>
[DataMember(Name = "Name")]
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the type
/// </summary>
[DataMember(Name = "Type")]
public string AdapterType { get; set; }
/// <summary>
/// Gets or sets DHCP info
/// </summary>
[DataMember(Name = "DHCP")]
public Dhcp Dhcp { get; set; }
// TODO - WINS
/// <summary>
/// Gets or sets Gateway info
/// </summary>
[DataMember(Name = "Gateways")]
public List<IpAddressInfo> Gateways { get; set; }
/// <summary>
/// Gets or sets the list of IP addresses
/// </summary>
[DataMember(Name = "IpAddresses")]
public List<IpAddressInfo> IpAddresses { get; set; }
}
#endregion // Data contract
}
}