Link to home
Start Free TrialLog in
Avatar of Loganathan Natarajan
Loganathan NatarajanFlag for India

asked on

How do i generate Ip addresses from Regular Expression

I am getting Regular Expression as an input for IP Address. ex. 192.168.(2[0-4]\d|25[0-5]|[01]?\d\d?).\.(2[0-4]\d|25[0-5]|[01]?\d\d?). Having this, i need to generate list of IP Addresses starting from 192.168.1.1 to 192.168.254.254. How could i achieve this in C#.NET.

Could anybody help?

Thanks in advance..
Avatar of ddrudik
ddrudik
Flag of United States of America image

You would need to loop through the target addresses to test each one against your pattern to determine a match.  Another option would be to have all IP addresses in a text file in which you match each line against the pattern.  There really isn't a simple function to do this well that I am aware of, what is the goal?

Note that . chars need to be escaped in regex patterns, as you did in one place but not the others, also in the one place where you did escape the . you seem to have an extra unescaped . before it.
Avatar of Loganathan Natarajan

ASKER

I am doing a program that will fetch the name of the computers available over a network. In order to get the computer name i need to provide the Ip address. There are many subnets available over the network. It is very difficult to enter all the IP addresses.
So, i thought i could use Regular Expression to avoid this difficulty.
I thought this could be generalized and used for any network.
ASKER CERTIFIED SOLUTION
Avatar of ddrudik
ddrudik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the question and the points.