If you’re like me, you constantly need your IP in Windows. When working with network interfaces and multiple servers, I find myself checking my IP a lot.
I built a little utility for myself that only shows the IP addresses on the host, rather than typing ipconfig and getting a long list, I can simply type “ip” and it will only show IP addresses.
C++ Version of the Tool
The following compiles with GCC for Windows, and probably a lot of other compilers as well. This utility is standalone and only needs to be copied into a folder within your path.
Create a file called ip.cpp and add the following:
usingSystem;namespaceiptools{classip{staticvoidMain(string[]args){//Create processSystem.Diagnostics.ProcesspProcess=newSystem.Diagnostics.Process();//the command we want to runpProcess.StartInfo.FileName="ipconfig";// we don't want this to output the original commandpProcess.StartInfo.UseShellExecute=false;//Set output of program to be written to process output streampProcess.StartInfo.RedirectStandardOutput=true;//Start the processpProcess.Start();//Get program outputstringstrOutput=pProcess.StandardOutput.ReadToEnd();// split it by linestring[]ourText=strOutput.Split('\n');Console.WriteLine("\n\n");foreach(stringlineinourText){if(line.Contains("IP")){Console.WriteLine(line+"\n");}}// close the processpProcess.Close();}}}
Compile this file from the command line (csc ip.cs) and it’s ready!
Summary
These files both provide a simple executable to output your ip address where you can read it quickly. If you have multiple adapters they will show up as well.
No comments:
Post a Comment