We often require the IP address of the current machine. If you’re tired of opening a DOS box and typing ipconfig, here’s a small tool that copies the IP address and puts it into the clipboard.
Just download the EXE file into your system path (eg %windir%\system32).
Then, go to Windows Start -> Run (Windows key + R) and type ipclip.
Here’s the source code…
String strHostName = Dns.GetHostName();
String ip = null;
Console.WriteLine("Local Machine's Host Name: " + strHostName);
// Then using host name, get the IP address list..
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
foreach (var addr in ipEntry.AddressList) {
if (!addr.AddressFamily.ToString().ToLower().EndsWith("v6"))
{
ip = addr.ToString();
break;
}
}
if (ip != null)
{
if (MessageBox.Show("IP Address: " + ip + " \r\n\r\nCopy to clipboard?", "IP Clip [msanjay.in]",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
Clipboard.SetData(DataFormats.Text, ip);
}
}
else
{
MessageBox.Show("IP Address not obtained", "IP Clip [msanjay.in]",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
this.Close();