Introduction

I have spent numerous hours searching for solutions to programming problems that I think should have a more accessible solution. This blog will contain my experiences and the solutions that I found. Your comments are welcome of course.

Saturday, February 9, 2008

Get Machine Name and IP Address

This is another part of the program I was writing earlier. I usually work on this program either on my work machine or on my laptop. I have a database that has the same design on either machine and I keep it updated. I ran into the problem of having to go and change the connection string for my Datasets every single time that I would switch machines for testing. So instead of going through that I wanted to find a way to switch the connection string automatically. To that extend I wrote the following code.
Imports System.Net

Dim MachineIPList() As IPAddress>
Dim MachineHostName As String
Dim MachineIP As IPAddress

MachineHostName = DNS.GetHostName()
MachineIPList = DNS.GetHostEntry(MachineHostName).AddressList

For Each MachineIP In MachineIPList
Control.Text = MachineIP.ToString()
Next