1.

Solve : IP Address from File?

Answer»

I am attempting to pull an IP address from a file and then use that IP address later in the script for different things such as tracert and ping etc.

I am pulling the IP from data.cfg by looking for Server.DB=

Code: [Select]type %filename%\data.cfg | find "SERVER.DB">>%LOG%

for /f "tokens=1,2 delims==" %%T in ('type %filename%\data.cfg ^| find "SERVER.DB"') do set string=%%U

Set IP=%string:~0,12%
SERVER.DB line can look like this
SERVER.DB=XX.XXX.XX.XX ; DB Files
OR
SERVER.DB=XXX.XX.XXX.XX

Now the above does technically work in most cases, but I have no idea what to do if the IP is longer then 12 Characters. (Probably 90% the IP will be 12 Char)



Irrespective of how many chars it has, an IP address (also known as a "dotted quad") is 4 tokens and the delims are periods/full stops/dots. Since you clearly understand how to use FOR, you know how to use this knowledge.

Nope can't SAY that my knowledge is that good. Still learning. Quote from: nothlit

SERVER.DB line can look like this
SERVER.DB=XX.XXX.XX.XX ; DB Files
OR
SERVER.DB=XXX.XX.XXX.XX

So, are you saying that a SERVER.DB line always has SERVER.DB at the beginning, then a = sign and then you will always find the IP address? Is that right?

That is a correct statement. In fact it is very easy to isolate the IP address. In your code, simply CHANGE this:

"tokens=1,2 delims=="

to this:

"tokens=1,2 delims== "

so that there are now 2 possible token delimiters, the = sign and also white space, therefore in any lines which have anything after the IP address, e.g. ;DB Files that will not be in the second token %%U

Thank you Sir once again for your help. I can start a new thread for this as it is on a pretty large tangent, but basically is there a way to get the version of an application from dos? From Windows you can hover over an *exe or go to the version tab in properties, but can dos pull this information and output to a file?

Telnet, I use telnet from a command PROMPT to confirm connectivity to a certain server on a certain port, if the connection fails visually on the dos prompt it will tell you, but if it works your no longer in dos, is there a way to batch this to log to a file saying telnet success or telnet failed? Then continue in the original dos prompt. I'm assuming to some DEGREE errorlevel could be used by maybe calling another bat file, but if it is successful I have no idea how to get back out of telnet to continue with the script.



Discussion

No Comment Found