Click here to Skip to main content
15,897,518 members
Articles / Programming Languages / C#
Article

Get all IP-Adresses within a given text

Rate me:
Please Sign up or sign in to vote.
1.00/5 (10 votes)
2 Mar 20052 min read 25.5K   622   7   2
Sometimes it's needed to get IP-Addresses within a text for further use

Introduction

At the beginning I tried to get the source-code from a webserver for a page. After this tests succeeded I got the idea to extract the Ip Address out of that source code for further uses like little IP programs that connects to "IP showing pages" and get the IP from there.

Details

This class I provided in the ZIP files is able to get all IP Addresses in a given text. The usage is very simple

C#
/*Over the IpFilter could be some code mabe to declerate a variable or sth. Let's say we have a string called myString*/
IpFilter myFilter = new IpFilter(myString);

//after that all properties are usable
//now I use the existing Variable to build my string 
foreach(object o in myFilter.IpList)
{
 myString = myString + "\n" + ((IPAddress)o).ToString();
}
 
//This will show us a MessageBox which contains all found IP Addresses
System.Windows.Forms.MessageBox.Show(myString);

/*The class has also the possibility to get all IP Addresses in a string with
a seperator ("|"). So you can use this option when you won't use an extra 
using directive.*/ 

With this class it's now easily possible to get an IP Address out of any text. When I needed such solution I didn't find something for .NET, so I made this class for everyone with the same problem. Feel free to use the class without any restrictions :)


Author

My name is Markus Seidl, and I live in Munich (Germany, Bavaria). My history is long, and theres no time to talk all about it. The next problem is already waiting to be solved ;). Now serious.

My beginning with coding was in 1995. After a year with my first own IBM Computer (YEAH a hot machine with a beeping hdd, big RAM with about 64 KiloBytes and a monochrome display) my brother make me program which simply sums 2 variables. From there on the computer was a "wonder machine" for me. It lasted till 1998 to get my second BIG step for further coding. I came from the gymnasium to secondary school. I got my first informatic lessons. From there on coding was always present but there was no way to make it everyday.

After working in a supermarket I got enought money to buy me the first Real PC, and started html coding. During my apprenticeship as IT specialist for system integration I got all the possibilities to learn many programming languages. When we learned java I got the language which I'll never would code with. So i decided do make it with C++ MFC. I'll made some little programs, and then I'll stopped, because it was boring. There was a long time without coding, till last year after I heard from .NET. I'll made some tries with the new language C#, and for first, i'll take no other language.

Today I have big machine on my right side, some rare tools on it, and can get lot of lore out of it. So then cya till next time.

P.S. life's sh*tty, but the graphic is wonderful ;)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Paul E. Bible22-Apr-09 10:28
Paul E. Bible22-Apr-09 10:28 
A regular expression would be so much easier
GeneralWhy easy if there is also an complicated way... Pin
Jochen Kalmbach [MVP VC++]3-Mar-05 0:01
Jochen Kalmbach [MVP VC++]3-Mar-05 0:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.