using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^ ([\w-_ ]+):\n\n +Type: Ethernet\n +Hardware.+\n +BSD Device Name: (.+)\n +IPv4 Addresses: (192[\.\d]+)$";
string input = @"ETHERNET CONNECTED, NO WI-FI
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Below Source Text from Mac Shell Script:
system_profiler SPNetworkDataType
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Network:
Thunderbolt Ethernet Slot 1:
Type: Ethernet
Hardware: Ethernet
BSD Device Name: en8
IPv4 Addresses: 192.168.1.15
IPv4:
AdditionalRoutes:
DestinationAddress: 192.168.1.15
SubnetMask: 255.255.255.255
DestinationAddress: 169.254.0.0
SubnetMask: 255.255.0.0
Addresses: 192.168.1.15
ARPResolvedHardwareAddress: 2c:b0:5d:25:af:69
ARPResolvedIPAddress: 192.168.1.1
Configuration Method: DHCP
ConfirmedInterfaceName: en8
Interface Name: en8
Network Signature: IPv4.Router=192.168.1.1;IPv4.RouterHardwareAddress=2c:b0:5d:25:af:69
Router: 192.168.1.1
Subnet Masks: 255.255.255.0
IPv6:
Configuration Method: Automatic
DNS:
Server Addresses: 192.168.1.1
DHCP Server Responses:
Domain Name Servers: 192.168.1.1
Lease Duration (seconds): 0
DHCP Message Type: 0x05
Routers: 192.168.1.1
Server Identifier: 192.168.1.1
Subnet Mask: 255.255.255.0
Ethernet:
MAC Address: 00:50:b6:ca:f0:dc
Media Options: Full Duplex, Flow Control
Media Subtype: 1000baseT
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Sleep Proxies:
1 Family Room Apple TV:
Marginal Power: 60
Metric: 703560
Portability: 35
Total Power: 63
Type: 70
Service Order: 0
Wi-Fi:
Type: AirPort
Hardware: AirPort
BSD Device Name: en0
IPv4 Addresses: 192.168.1.16
IPv4:
AdditionalRoutes:
DestinationAddress: 192.168.1.16
SubnetMask: 255.255.255.255
DestinationAddress: 169.254.0.0
SubnetMask: 255.255.0.0
Addresses: 192.168.1.16
ARPResolvedHardwareAddress: 2c:b0:5d:25:af:69
ARPResolvedIPAddress: 192.168.1.1
Configuration Method: DHCP
ConfirmedInterfaceName: en0
Interface Name: en0
Network Signature: IPv4.Router=192.168.1.1;IPv4.RouterHardwareAddress=2c:b0:5d:25:af:69
Router: 192.168.1.1
Subnet Masks: 255.255.255.0
IPv6:
Configuration Method: Automatic
DNS:
Server Addresses: 192.168.1.1
DHCP Server Responses:
Domain Name Servers: 192.168.1.1
Lease Duration (seconds): 0
DHCP Message Type: 0x05
Routers: 192.168.1.1
Server Identifier: 192.168.1.1
Subnet Mask: 255.255.255.0
Ethernet:
MAC Address: 28:cf:e9:17:e0:d1
Media Options:
Media Subtype: Auto Select
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 2
Thunderbolt Ethernet:
Type: Ethernet
Hardware: Ethernet
BSD Device Name: en6
IPv4:
Configuration Method: DHCP
IPv6:
Configuration Method: Automatic
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 1
Wi-Fi:
Type: AirPort
Hardware: AirPort
BSD Device Name: en0
IPv4:
Configuration Method: DHCP
IPv6:
Configuration Method: Automatic
Ethernet:
MAC Address: 28:cf:e9:17:e0:d1
Media Options:
Media Subtype: Auto Select
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 2
USB Ethernet:
Type: Ethernet
Hardware: Ethernet
BSD Device Name: en3
IPv4:
Configuration Method: DHCP
IPv6:
Configuration Method: Automatic
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 3
AX88179 USB 3.0 to Gigabit Ethernet:
Type: Ethernet
Hardware: Ethernet
BSD Device Name: en7
IPv4:
Configuration Method: DHCP
IPv6:
Configuration Method: Automatic
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 4
Thunderbolt FireWire:
Type: FireWire
Hardware: FireWire
BSD Device Name: fw0
IPv4:
Configuration Method: DHCP
IPv6:
Configuration Method: Automatic
Ethernet:
MAC Address: 00:50:b6:10:00:00:5d:31
Media Options: Full Duplex
Media Subtype: Auto Select
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 5
iPhone:
Type: Ethernet
Hardware: Ethernet
BSD Device Name: en5
IPv4:
Configuration Method: DHCP
IPv6:
Configuration Method: Automatic
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 6
Bluetooth PAN:
Type: Ethernet
Hardware: Ethernet
BSD Device Name: en4
IPv4:
Configuration Method: DHCP
IPv6:
Configuration Method: Automatic
Proxies:
Exceptions List: *.local, 169.254/16
FTP Passive Mode: Yes
Service Order: 7
~~~~~~~~~~~~~~~~~~~~~~~~
Type: Ethernet\n +Hardware.+\n +BSD.+\n +IPv4 Addresses: 192[\.\d]+$";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx