Programmers: I need some help with a Windows Tool
Oldbitcollector (Jeff)
Posts: 8,091
Guys,
There is a LOT of programming talent here, and I need your help.
I need a Windows tool that does the following...
Checks your LAN and returns the following information (In a window)
Recommended IP address: 192.168.1.X
(Please use the follow criteria to determine the recommended address:
* Check the workstation's address.
If it is in the 10's make X a number around 100
If it is in the 100's make X a number around 200
Check to see if the address is already alive, move forward if it is.)
The idea here is to find an open number, away from other IPs on the lan.
Report the Subnet Mask (255.255.255.0 -- yada yada)
Report the Gateway
Report the Outside IP address (The one that is live to the Internet)
The window should have four pieces of information:
Recommended IP
Subnet Mask
Current Gateway
Outside "live" IP Address
I can't promise any riches for this, but I will put your name in "lights" in the credits of material I'm creating for the Spinneret.
Thanks
OBC
There is a LOT of programming talent here, and I need your help.
I need a Windows tool that does the following...
Checks your LAN and returns the following information (In a window)
Recommended IP address: 192.168.1.X
(Please use the follow criteria to determine the recommended address:
* Check the workstation's address.
If it is in the 10's make X a number around 100
If it is in the 100's make X a number around 200
Check to see if the address is already alive, move forward if it is.)
The idea here is to find an open number, away from other IPs on the lan.
Report the Subnet Mask (255.255.255.0 -- yada yada)
Report the Gateway
Report the Outside IP address (The one that is live to the Internet)
The window should have four pieces of information:
Recommended IP
Subnet Mask
Current Gateway
Outside "live" IP Address
I can't promise any riches for this, but I will put your name in "lights" in the credits of material I'm creating for the Spinneret.
Thanks
OBC

Comments
Dynamic Host Configuration Protocol ( DHCP) inthe router handles assigning IP addresses, unless they are manually
assigned or the router allows DHCP Reservation.
I use DHCP Reservation to make sure that IP addresses remain constant without manually assigining them (see image).
The only method I can envision that might work is a kludge - basically displaying HTML IP status pages from your particular router in a browser object and then parsing the web page using the Document Object Model (DOM) to extract the addresses. This method would be specific to your router (and firmware version).
Extracting data in this fashion is sometimes called "screen scraping" or "web scraping" http://en.wikipedia.org/wiki/Web_scraping
Should be able to make a determination from that address which are being used.. If it's in the 10's then the safety region is around 100. If it's in the 100's then the safety region should be around 200. A simple PING should be able to confirm the address is likely unused.
OBC
IP addresses don't have to be assigned sequentially so there is no way "to determine" what ranges are in use (or reserved). A PING is not a reliable way since many security programs block PING requests to prevent hacker attacks.
- Ron
PS There are other reserved Private IP addresses (as specified by the Internet Assigned Numbers Authority (IANA)) you might be able to use besides 192.168.0.0 – 192.168.255.255.
They are:
10.0.0.0 – 10.255.255.255
172.16.0.0 – 172.31.255.255
Home networking routers typically hand out addresses starting either in the 10's or 100's. I know there is no exact way to determine an address, but we can take some reasonable "guesses" for home users based on the workstation's IP address. Anyone using the device on a larger network should contact their network administrator to make sure they don't cause a problem.
In my experience home routers generally don't hand out more than a few addresses given most of us don't have more than a handful of devices.
OBC
The other displays your WAN IP Address by using an HTTPRequest to browse to http://checkip.dyndns.org/ to get your WAN (Wide Area Network) address which is what I think you are calling the "Outside IP address".
Copy this code into notepad and save them as WANIP.vbs and GetIP.vbs and double click them to run.
This may get you started...
WANIP.vbs
option explicit Const strURL = "[URL]http://checkip.dyndns.org/[/URL]" Dim resp, i, cnt, objArgs, duration, btn Dim WSHShell, objHTTP duration = 10 Set WSHShell = wscript.CreateObject("WScript.Shell") Set objHTTP = CreateObject("MSXML2.XMLHTTP.3.0") objHTTP.open "GET", strURL, False 'in case of error once, retry every second... On Error Resume Next cnt = 1 objHTTP.send If err.Number <> 0 Then Do While err.Number <> 0 objHTTP.send WScript.Sleep 1000 cnt = cnt + 1 msgbox cnt if cnt >3 then WSHShell.PopUP "Could not connect to " & strURL, 10, "WAN IP Address", 0 ' + 64 wscript.quit end if Loop End If resp = objHTTP.responseText i = instr(resp, "IP Address: ") if i > 0 then resp = mid(resp, i+12) end if i = instr(resp, "</body>") if i > 0 then resp = mid(resp, 1, i-1) end if 'resp = resp & vbcrlf & vbcrlf & strURL 'msgbox objHTTP.readyState & vbcrlf & objHTTP.statusText & vbcrlf & objHTTP.status btn = WSHShell.PopUP(resp, duration, "WAN IP Address", 1) ' + 64 set WSHShell = nothingGetIP.vbs
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set IPConfigSet = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) WScript.Echo IPConfig.IPAddress(i) Next End If NextAh ha! Yes.. This is going the direction we need. Getting an error in GetIP.vbs though..
OBC
GetIP.vbs
Windows Script Host
Script: C:\GetIP.vbs
Line: 8
Char: 1
Error: 0x80041013
Code: 80041013
Source: (null)
OBC
Try running "IPCONFIG /ALL>C:\Jeff.txt" from a DOS prompt. This will create C:\Jeff.txt with the IPConfig output. Open Jeff.txt with notepad and post the results...
Windows IP Configuration Host Name . . . . . . . . . . . . : family-4003ac1f Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Unknown IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No Ethernet adapter Local Area Connection 3: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connection Physical Address. . . . . . . . . : 00-13-D4-47-D8-F1 Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.2.8 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.2.1 DHCP Server . . . . . . . . . . . : 192.168.2.1 DNS Servers . . . . . . . . . . . : 192.168.2.1 Lease Obtained. . . . . . . . . . : Tuesday, July 05, 2011 3:49:13 PM Lease Expires . . . . . . . . . . : Friday, July 08, 2011 3:49:13 PMTry running this version - the WHERE clause is commented out.
Does it display 192.168.2.8?
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set IPConfigSet = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration") ' Where IPEnabled=TRUE") For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) ' WScript.Echo IPConfig.IPAddress(i) msgbox IpConfig.Caption & vbcrlf & IPConfig.IPAddress(i), vbinformation, IPConfig.DNSHostName Next End If NextSince your IPConfig output looks simple and straightforward, I am stumped.
Run it from the command line.
We're getting closer..
OBC
option explicit dim WSHShell, sExec, x, strLineIn dim msgtxt Set WSHShell = CreateObject("WScript.Shell") set sExec = WSHShell.Exec("ipconfig /all") Do While Not sExec.StdOut.AtEndOfStream strLineIn = sExec.StdOut.ReadLine() if instr(strLineIn, "IP Address") > 0 then msgtxt = msgtxt & "IP Addr: " & ParseIt(strLineIn) & vbcrlf end if if instr(strLineIn, "Subnet Mask") > 0 then msgtxt = msgtxt & "Subnet mask: " & ParseIt(strLineIn) & vbcrlf end if if instr(strLineIn, "Description") > 0 then msgtxt = msgtxt & "Adapter: " & ParseIt(strLineIn) & vbcrlf end if Loop msgbox msgtxt, vbinformation, "IP Address" public function ParseIt(strIN) dim i i = instr(strIN, ":") if i > 0 then Parseit = trim(mid(strIN, i+1)) else ParseIt = strIN end if end functionThat's the ticket!
Now we just need to make an "educated" guess as to an available IP outside of the typical address ranges..
OBC
it replaces the last node with 254 for a recommended address
e.g. 192.168.1.100 --> 192.168.1.254
This is rather a crude way to do this. A compiled program doing API calls would be better - especially since the WMI approach did not work for you...
Also you might have multiple adapters.
option explicit dim WSHShell, sExec, x, strLineIn, IPaddr, subnet, adapter, iparray, foundsw, recommend dim msgtxt Set WSHShell = CreateObject("WScript.Shell") set sExec = WSHShell.Exec("ipconfig /all") foundsw = false Do While Not sExec.StdOut.AtEndOfStream strLineIn = sExec.StdOut.ReadLine() if instr(strLineIn, "Description") > 0 then Adapter = ParseIt(strLineIn) end if if instr(strLineIn, "IP Address") > 0 then ipaddr = ParseIt(strLineIn) iparray = split(ipaddr, ".", -1, 1) if ubound(iparray) = 3 then foundsw = true recommend = iparray(0) & "." & iparray(1) & "." & iparray(2) & "." & "254" end if end if if instr(strLineIn, "Subnet Mask") > 0 then subnet = ParseIt(strLineIn) if foundsw then exit do end if end if Loop msgtxt = "Adapter: " & adapter & vbcrlf & "IP Address: " & IPaddr & vbcrlf & _ "Subnet mask: " & subnet & vbcrlf & "Recommended: " & recommend msgbox msgtxt, vbinformation, "IP Address" public function ParseIt(strIN) dim i i = instr(strIN, ":") if i > 0 then Parseit = trim(mid(strIN, i+1)) else ParseIt = strIN end if end functionNot bad.. Can you slip the Gateway and Outside IP into this single script?
OBC
Here you go!
The bill is on the way - I don't take PAYPAL
- Ron
option explicit Const strURL = "[URL]http://checkip.dyndns.org/[/URL]" dim WSHShell, sExec, x, strLineIn, IPaddr, subnet, adapter, gateway, iparray, foundsw, recommend dim msgtxt, temp dim objHTTP, cnt, resp, WAN, i Set WSHShell = CreateObject("WScript.Shell") ' get WAN IP address using HTTPRequest Set objHTTP = CreateObject("MSXML2.XMLHTTP.3.0") objHTTP.open "GET", strURL, False 'in case of error once, retry every second... On Error Resume Next cnt = 1 objHTTP.send If err.Number <> 0 Then Do While err.Number <> 0 objHTTP.send WScript.Sleep 1000 cnt = cnt + 1 msgbox cnt if cnt >3 then WSHShell.PopUP "Could not connect to " & strURL, 10, "WAN IP Address", 0 ' + 64 wscript.quit end if Loop End If WAN = objHTTP.responseText i = instr(WAN, "IP Address: ") if i > 0 then WAN = mid(WAN, i+12) end if i = instr(WAN, "</body>") if i > 0 then WAN = mid(WAN, 1, i-1) end if 'execute IPCONFIG /ALL and extract info from Exec output stream set sExec = WSHShell.Exec("ipconfig /all") foundsw = false Do While Not sExec.StdOut.AtEndOfStream strLineIn = sExec.StdOut.ReadLine() if instr(strLineIn, "Description") > 0 then Adapter = ParseIt(strLineIn) end if if instr(strLineIn, "IP Address") > 0 then temp = ParseIt(strLineIn) iparray = split(temp, ".", -1, 1) 'IPv4 format "." separator - NOT IPv6 which uses ":" if ubound(iparray) = 3 then IPaddr = temp foundsw = true recommend = iparray(0) & "." & iparray(1) & "." & iparray(2) & "." & "254" end if end if if instr(strLineIn, "Subnet Mask") > 0 then subnet = ParseIt(strLineIn) end if if instr(strLineIn, "Default Gateway") > 0 then gateway = ParseIt(strLineIn) if foundsw then exit do 'found IP address and related info - stop processing stream end if end if Loop msgtxt = "Adapter: " & adapter & vbcrlf & "IP Address: " & IPaddr & vbcrlf & _ "Subnet mask: " & subnet & vbcrlf & _ "Gateway: " & gateway & vbcrlf & _ "WAN address: " & WAN & vbcrlf & vbcrlf & _ "Recommended: " & recommend msgbox msgtxt, vbinformation, "LAN/WAN info" public function ParseIt(strIN) dim i i = instr(strIN, ":") if i > 0 then Parseit = trim(mid(strIN, i+1)) else ParseIt = strIN end if end functionIf you have Microsoft TCP/IP version 6 installed, it complicates the IPCONFIG results, but the script handles it.
e.g.
Windows IP Configuration Host Name . . . . . . . . . . . . : czapala1 Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Unknown IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller Physical Address. . . . . . . . . : 00-1D-92-71-AD-F6 Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.1.100 Subnet Mask . . . . . . . . . . . : 255.255.255.0 IP Address. . . . . . . . . . . . : fe80::21d:92ff:fe71:adf6%4 Default Gateway . . . . . . . . . : 192.168.1.1 DHCP Server . . . . . . . . . . . : 192.168.1.1 DNS Servers . . . . . . . . . . . : 208.67.222.222 74.128.17.114 208.67.220.220 fec0:0:0:ffff::1%1 fec0:0:0:ffff::2%1 fec0:0:0:ffff::3%1 Lease Obtained. . . . . . . . . . : Wednesday, July 06, 2011 7:56:17 AM Lease Expires . . . . . . . . . . : Friday, July 08, 2011 7:56:17 AM Tunnel adapter Teredo Tunneling Pseudo-Interface: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface Physical Address. . . . . . . . . : FF-FF-FF-FF-FF-FF-FF-FF Dhcp Enabled. . . . . . . . . . . : No IP Address. . . . . . . . . . . . : fe80::ffff:ffff:fffd%5 Default Gateway . . . . . . . . . : NetBIOS over Tcpip. . . . . . . . : Disabled Tunnel adapter Automatic Tunneling Pseudo-Interface: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : Automatic Tunneling Pseudo-Interface Physical Address. . . . . . . . . : C0-A8-01-64 Dhcp Enabled. . . . . . . . . . . : No IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2 Default Gateway . . . . . . . . . : DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1 fec0:0:0:ffff::2%1 fec0:0:0:ffff::3%1 NetBIOS over Tcpip. . . . . . . . : Disabledhttp://forums.parallax.com/attachment.php?attachmentid=82686&d=1309959165
and if you can how do you do it
I am not trying to hijack this post
Mike, it looks like you wrote this in Visual Studio 2010 .NET so I am curious, why does it need to run from a command line?
Maybe it would appeal more to Jeff if it displayed in a window.
I haven't done much with dotnet - I still use VB6 alot - old habits are to break.
I don't think these suggested addresses from your program are legitimate
Suggested IP(s) ............... : 254.128.0.10
Suggested IP(s) ............... : 254.128.0.10
Suggested IP(s) ............... : 254.128.0.10
Suggested IP(s) ............... : 0.0.0.10
Suggested IP(s) ............... : 254.128.0.10
Could you post the source code?
Does this script also work successfully on Windows 7?
OBC
Don't know - maybe someone can try it and let us know.
I am still a big fan of XP Pro. VISTA was terrible but Windows 7 sounds good - but I am afraid that some development tools I still use may not work under WIN7.
There are still a LOT of XP users out there...
It doesn't really... I did not put in a pause so when the program completes the console goes away. That's an easy thing to fix... lazy I guess. I'll post the source when I get home from work.
I simply executed the logic given by OBC's requirements. I can easily filter out the x.x.x.0 IPs.
It is in a window? do you mean a Win form?
The only valid Private IP addresses according to the IANA are:
192.168.0.0 192.168.255.255.
10.0.0.0 10.255.255.255
172.16.0.0 172.31.255.255
I can add IP filtering to a config file so that way thte user can restrict the results. Plus I will not allow redundant entries or adapters that are not "UP".
Ron, fyi, I'm getting a recommend IP of 170.68.14.254 but I'm at work.
I've seen some printer installs want that address.
OBC