Dear all
I want to use ruby regular expression to get ipconfig information from a
string. I wrote some code, but it is not works well. would anybody help
me, thanks!
the coding is like that
$msdos=“ipconfig /all”
str_ipcfg=eval(""+$msdos+"
")
str_ipcfg.scan %r{
^ \S [^:]* : \s* $
(?:
^ \s+ [^:]+ : [^:]+ $ [\n\r]+
)*
}x do |adapter|
p adapter
- if use $msdos=“ipconfig”, get a string like the following:
“Windows IP Configuration\n\n\nWireless LAN adapter 2:\n\n Media
State . . . . . . . . . . . : Media disconnected\n Connection-specific
DNS Suffix . : \n\n”
“Ethernet adapter Bluetooth :\n\n Media State . . . . . . . . . . . :
Media disconnected\n Connection-specific DNS Suffix . : \n\n”
“Wireless LAN adapter :\n\n Connection-specific DNS Suffix . : \n
IPv4 Address. . . . . . . . . . . : 192.168.1.50\n Subnet Mask . . . .
. . . . . . . : 255.255.255.0\n Default Gateway . . . . . . . . . :
192.168.1.1\n”
Process finished with exit code 0
- if use "$msdos=“ipconfig /all”, the string like that:
“Wireless LAN adapter 2:\n\n Media State . . . . . . . . . . . :
Media disconnected\n Connection-specific DNS Suffix . : \n
Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport
Adapter\n Physical Address. . . . . . . . . : 16-2F-68-CB-81-37\n
DHCP Enabled. . . . . . . . . . . : Yes\n Autoconfiguration Enabled .
. . . : Yes\n\n”
“Ethernet adapter Bluetooth :\n\n Media State . . . . . . . . . . . :
Media disconnected\n Connection-specific DNS Suffix . : \n
Description . . . . . . . . . . . : Bluetooth Device (Personal Area
Network)\n Physical Address. . . . . . . . . : 74-2F-68-CC-41-BF\n
DHCP Enabled. . . . . . . . . . . : Yes\n Autoconfiguration Enabled .
. . . : Yes\n\n”
“Wireless LAN adapter :\n\n Connection-specific DNS Suffix . : \n
Description . . . . . . . . . . . : Atheros AR9485WB-EG Wireless Network
Adapter\n Physical Address. . . . . . . . . : 74-2F-68-CB-81-37\n
DHCP Enabled. . . . . . . . . . . : Yes\n Autoconfiguration Enabled .
. . . : Yes\n IPv4 Address. . . . . . . . . . . :
192.168.1.50(Preferred) \n Subnet Mask . . . . . . . . . . . :
255.255.255.0\n”
my question is : where is wrong in my 2ed regular express, causing the
string is not complete, i could not get the whole ipconfig information?
because the gateway, dhcp, dns information is after the subnet mask
information.
many thanks!
Have a nice day.
Edward