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

lduchosal / ipnetwork / 22803352265

07 Mar 2026 05:07PM UTC coverage: 91.848% (-1.3%) from 93.118%
22803352265

push

travis-pro

web-flow
Merge pull request #383 from lduchosal/feat/v4-nullable

feat/v4-nullable

651 of 721 branches covered (90.29%)

Branch coverage included in aggregate %.

111 of 147 new or added lines in 26 files covered. (75.51%)

5 existing lines in 3 files now uncovered.

1929 of 2088 relevant lines covered (92.39%)

574342.5 hits per line

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

44.64
/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
    {
16✔
30
        if (!InternalParse(false, ipaddress, netmask, out IPNetwork2? ipnetwork))
16!
NEW
31
        {
×
NEW
32
            throw new ArgumentException("Failed to parse IP address and netmask.", nameof(ipaddress));
×
33
        }
34

35
        return ipnetwork;
3✔
36
    }
3✔
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
    {
30✔
53
        if (!InternalParse(false, ipaddress, cidr, out IPNetwork2? ipnetwork))
30!
NEW
54
        {
×
NEW
55
            throw new ArgumentException("Failed to parse IP address and CIDR.", nameof(ipaddress));
×
56
        }
57

58
        return ipnetwork;
26✔
59
    }
26✔
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
    {
6✔
76
        if (!InternalParse(false, ipaddress, netmask, out IPNetwork2? ipnetwork))
6!
NEW
77
        {
×
NEW
78
            throw new ArgumentException("Failed to parse IP address and netmask.", nameof(ipaddress));
×
79
        }
80

81
        return ipnetwork;
2✔
82
    }
2✔
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
    {
4,001,013✔
99
        if (!InternalParse(false, network, CidrGuess.ClassFull, true, out IPNetwork2? ipnetwork))
4,001,013!
UNCOV
100
        {
×
NEW
101
            throw new ArgumentException("Failed to parse network.", nameof(network));
×
102
        }
103

104
        return ipnetwork;
4,001,006✔
105
    }
4,001,006✔
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
    {
×
NEW
123
        if (!InternalParse(false, network, CidrGuess.ClassFull, sanitize, out IPNetwork2? ipnetwork))
×
124
        {
×
NEW
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
    {
16✔
147
        if (!InternalParse(false, network, cidrGuess, true, out IPNetwork2? ipnetwork))
16!
UNCOV
148
        {
×
NEW
149
            throw new ArgumentException("Failed to parse network.", nameof(network));
×
150
        }
151

152
        return ipnetwork;
16✔
153
    }
16✔
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
    {
×
NEW
172
        if (!InternalParse(false, network, cidrGuess, sanitize, out IPNetwork2? ipnetwork))
×
173
        {
×
NEW
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