• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lduchosal / ipnetwork / 960

15 May 2026 07:18AM UTC coverage: 0.0% (-94.1%) from 94.053%
960

Pull #411

appveyor

web-flow
Merge ef6b054ce into 4cec191ae
Pull Request #411: Bump MSTest.TestFramework from 4.2.2 to 4.2.3

0 of 2438 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/System.Net.IPNetwork/IPNetwork2Parse.cs
1
// <copyright file="IPNetwork2Parse.cs" company="IPNetwork">
2
// Copyright (c) IPNetwork. All rights reserved.
3
// </copyright>
4

5
namespace System.Net;
6

7
/// <summary>
8
/// the parse methods.
9
/// </summary>
10
public partial class IPNetwork2
11
{
12
    /// <summary>
13
    /// 192.168.168.100 - 255.255.255.0
14
    ///
15
    /// ```
16
    /// Network   : 192.168.168.0
17
    /// Netmask   : 255.255.255.0
18
    /// Cidr      : 24
19
    /// Start     : 192.168.168.1
20
    /// End       : 192.168.168.254
21
    /// Broadcast : 192.168.168.255
22
    /// ```.
23
    ///
24
    /// </summary>
25
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
26
    /// <param name="netmask">A string representing a netmask in std format (255.255.255.0).</param>
27
    /// <returns>An IPNetwork equivalent to the network contained in ipaddress/netmask.</returns>
28
    public static IPNetwork2 Parse(string ipaddress, string netmask)
29
    {
×
30
        if (!InternalParse(false, ipaddress, netmask, out IPNetwork2? ipnetwork))
×
31
        {
×
32
            throw new ArgumentException("Failed to parse IP address and netmask.", nameof(ipaddress));
×
33
        }
34

35
        return ipnetwork;
×
36
    }
×
37

38
    /// <summary>
39
    /// 192.168.168.100/24
40
    ///
41
    /// Network   : 192.168.168.0
42
    /// Netmask   : 255.255.255.0
43
    /// Cidr      : 24
44
    /// Start     : 192.168.168.1
45
    /// End       : 192.168.168.254
46
    /// Broadcast : 192.168.168.255.
47
    /// </summary>
48
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
49
    /// <param name="cidr">A byte representing the netmask in cidr format (/24).</param>
50
    /// <returns>An IPNetwork equivalent to the network contained in ipaddress/cidr.</returns>
51
    public static IPNetwork2 Parse(string ipaddress, byte cidr)
52
    {
×
53
        if (!InternalParse(false, ipaddress, cidr, out IPNetwork2? ipnetwork))
×
54
        {
×
55
            throw new ArgumentException("Failed to parse IP address and CIDR.", nameof(ipaddress));
×
56
        }
57

58
        return ipnetwork;
×
59
    }
×
60

61
    /// <summary>
62
    /// 192.168.168.100 255.255.255.0
63
    ///
64
    /// Network   : 192.168.168.0
65
    /// Netmask   : 255.255.255.0
66
    /// Cidr      : 24
67
    /// Start     : 192.168.168.1
68
    /// End       : 192.168.168.254
69
    /// Broadcast : 192.168.168.255.
70
    /// </summary>
71
    /// <param name="ipaddress">A string containing an ip address to convert.</param>
72
    /// <param name="netmask">A netmask to be used to create the IPNetwork.</param>
73
    /// <returns>An IPNetwork equivalent to the network contained in ipaddress/netmask.</returns>
74
    public static IPNetwork2 Parse(IPAddress ipaddress, IPAddress netmask)
75
    {
×
76
        if (!InternalParse(false, ipaddress, netmask, out IPNetwork2? ipnetwork))
×
77
        {
×
78
            throw new ArgumentException("Failed to parse IP address and netmask.", nameof(ipaddress));
×
79
        }
80

81
        return ipnetwork;
×
82
    }
×
83

84
    /// <summary>
85
    /// 192.168.0.1/24
86
    /// 192.168.0.1 255.255.255.0
87
    ///
88
    /// Network   : 192.168.0.0
89
    /// Netmask   : 255.255.255.0
90
    /// Cidr      : 24
91
    /// Start     : 192.168.0.1
92
    /// End       : 192.168.0.254
93
    /// Broadcast : 192.168.0.255.
94
    /// </summary>
95
    /// <param name="network">A string containing an ip network to convert.</param>
96
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
97
    public static IPNetwork2 Parse(string network)
98
    {
×
99
        if (!InternalParse(false, network, CidrGuess.ClassFull, true, out IPNetwork2? ipnetwork))
×
100
        {
×
101
            throw new ArgumentException("Failed to parse network.", nameof(network));
×
102
        }
103

104
        return ipnetwork;
×
105
    }
×
106

107
    /// <summary>
108
    /// 192.168.0.1/24
109
    /// 192.168.0.1 255.255.255.0
110
    ///
111
    /// Network   : 192.168.0.0
112
    /// Netmask   : 255.255.255.0
113
    /// Cidr      : 24
114
    /// Start     : 192.168.0.1
115
    /// End       : 192.168.0.254
116
    /// Broadcast : 192.168.0.255.
117
    /// </summary>
118
    /// <param name="network">A string containing an ip network to convert.</param>
119
    /// <param name="sanitize">If true, removes invalid characters and normalizes whitespace from the network string, keeping only valid network address characters (0-9, a-f, A-F, ., /, :, and spaces).</param>
120
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
121
    public static IPNetwork2 Parse(string network, bool sanitize)
122
    {
×
123
        if (!InternalParse(false, network, CidrGuess.ClassFull, sanitize, out IPNetwork2? ipnetwork))
×
124
        {
×
125
            throw new ArgumentException("Failed to parse network.", nameof(network));
×
126
        }
127

128
        return ipnetwork;
×
129
    }
×
130

131
    /// <summary>
132
    /// 192.168.0.1/24
133
    /// 192.168.0.1 255.255.255.0
134
    ///
135
    /// Network   : 192.168.0.0
136
    /// Netmask   : 255.255.255.0
137
    /// Cidr      : 24
138
    /// Start     : 192.168.0.1
139
    /// End       : 192.168.0.254
140
    /// Broadcast : 192.168.0.255.
141
    /// </summary>
142
    /// <param name="network">A string containing an ip network to convert.</param>
143
    /// <param name="cidrGuess">A ICidrGuess implementation that will be used to guess CIDR during conversion.</param>
144
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
145
    public static IPNetwork2 Parse(string network, ICidrGuess cidrGuess)
146
    {
×
147
        if (!InternalParse(false, network, cidrGuess, true, out IPNetwork2? ipnetwork))
×
148
        {
×
149
            throw new ArgumentException("Failed to parse network.", nameof(network));
×
150
        }
151

152
        return ipnetwork;
×
153
    }
×
154

155
    /// <summary>
156
    /// 192.168.0.1/24
157
    /// 192.168.0.1 255.255.255.0
158
    ///
159
    /// Network   : 192.168.0.0
160
    /// Netmask   : 255.255.255.0
161
    /// Cidr      : 24
162
    /// Start     : 192.168.0.1
163
    /// End       : 192.168.0.254
164
    /// Broadcast : 192.168.0.255.
165
    /// </summary>
166
    /// <param name="network">A string containing an ip network to convert.</param>
167
    /// <param name="cidrGuess">A ICidrGuess implementation that will be used to guess CIDR during conversion.</param>
168
    /// <param name="sanitize">If true, removes invalid characters and normalizes whitespace from the network string, keeping only valid network address characters (0-9, a-f, A-F, ., /, :, and spaces).</param>
169
    /// <returns>An IPNetwork equivalent to the network contained in string network.</returns>
170
    public static IPNetwork2 Parse(string network, ICidrGuess cidrGuess, bool sanitize)
171
    {
×
172
        if (!InternalParse(false, network, cidrGuess, sanitize, out IPNetwork2? ipnetwork))
×
173
        {
×
174
            throw new ArgumentException("Failed to parse network.", nameof(network));
×
175
        }
176

177
        return ipnetwork;
×
178
    }
×
179
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc