In the internet there are several places that show you how to get an IP address. And a lot of them look like this example:
String strHostName = string.Empty;
Dns.GetHostEntry(Dns.GetHostName()).AddressList[1]
one line of code :D