Extract IP address from text file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
test123
Posts: 2
Joined: 28 Jul 2009 23:02

Extract IP address from text file.

#1 Post by test123 » 28 Jul 2009 23:08

Hi Script Experts,

I have on text file, it generated from wget.exe. ( It is my isp wan ip)

I need one script to extract only the ip address. ( just like 92.99.191.63) only.

Here some time ip will show 256.99.192.123

ip.txt
--------
<html><head><title>Current IP Check</title></head><body>Current IP Address: 92.99.191.63</body></html>

Thanks in advance.


Regards,

Baiju.

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#2 Post by ghostmachine4 » 29 Jul 2009 18:27

you can use vbscript

Code: Select all

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objRE = New RegExp
objRE.Pattern = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
objRE.Global     = True
objRE.IgnoreCase = False
objRE.MultiLine = True
strFile = "c:\test\file.txt"
strFileContents = objFS.OpenTextFile(strFile).ReadAll
Set colMatches = objRE.Execute(strFileContents)
For Each objMatch In colMatches
   WScript.Echo objMatch.Value
Next


test123
Posts: 2
Joined: 28 Jul 2009 23:02

#3 Post by test123 » 29 Jul 2009 22:39

Hi ghostmachine4,

Many thanks, It works !

Regards,

BAIJU

Post Reply