thankusomuch
Goto Top

Get ip from external txt file and use in vbscript

hi everybody,

i have a little problem but iam sure its very easy stuff for u guys.

I want to recieve the ip adress from an external txt file on my server (192.168.1.101/ip.txt)


externaltxtip= ' example: "http://148.102.73.247:7476/"


i dont really want to save the file on my pc. i just want the content and past it after externaltxtip=

how can i do that


and should i write
"http://148.102.73.247:7476/"
or just
http://148.102.73.247:7476/

thanks in advance.

Content-Key: 321844

Url: https://administrator.de/contentid/321844

Printed on: April 19, 2024 at 10:04 o'clock

Member: MrCount
MrCount Nov 23, 2016 updated at 13:47:08 (UTC)
Goto Top
Hi,

if your ip.txt is like

externaltxtip=http://148.102.73.247:7476/

and is in a shared folder, then maybe this works:
Const sInFile = "\\192.168.1.101\share\ip.txt"  
sText = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(sInFile, 1).ReadAll, "=")  
sIP = sText(1)
MsgBox sIP 
Member: thankusomuch
thankusomuch Nov 23, 2016 updated at 14:19:29 (UTC)
Goto Top
thanks for your help but i dont get it working.

look at this example:

Const sInFile = "http://192.168.2.101/ip.txt"
sText = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(sInFile, 1).ReadAll, "=")
sIP = sText(1)
MsgBox sIP


Dim iURL
Dim objShell
iURL =
set objShell = CreateObject("WScript.Shell")
objShell.run(iURL)


'the ip.txt is on a virtual server.


How can i make it opening the ip from the txt. iam not an expert face-sad

this is what i found:


url = "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=nrcGOV"
'xmlHttp.setProxy 2, "www.proxy.nrc.gov:80"

Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.Open "GET", url, False
objHTTP.Send
rss = BinaryToString(objHTTP.ResponseBody)
Response.Write(rss)

Function BinaryToString(byVal Binary)
'--- Converts the binary content to text using ADODB Stream

'--- Set the return value in case of error
BinaryToString = ""

'--- Creates ADODB Stream
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'--- Specify stream type
BinaryStream.Type = 1 '--- adTypeBinary

'--- Open the stream And write text/string data to the object
BinaryStream.Open
BinaryStream.Write Binary

'--- Change stream type to text
BinaryStream.Position = 0
BinaryStream.Type = 2 '--- adTypeText

'--- Specify charset for the source text (unicode) data
BinaryStream.CharSet = "UTF-8"

'--- Return converted text from the object
BinaryToString = BinaryStream.ReadText
End Function


but i dont know how to use it.
Mitglied: 131381
131381 Nov 23, 2016 updated at 14:38:30 (UTC)
Goto Top
strIP = DownloadString("http://192.168.2.101/ip.txt")  
Msgbox strIP

Function DownloadString(strURL)
    Dim objhttp
    Set objhttp = CreateObject("Microsoft.XMLHTTP")  
    With objhttp
        .Open "GET", strURL, False  
        .send
        If .Status = 200 Then
            DownloadString = .responseText
        Else
            DownloadString = ""  
        End If
    End With
End Function
Regards
Member: thankusomuch
thankusomuch Nov 23, 2016 at 15:59:24 (UTC)
Goto Top
thank u so much guys. looks pretty close to what i need.
but how can i make it opening in the browser instead of a message box?

many thanks
Member: thankusomuch
thankusomuch Nov 23, 2016 at 19:25:16 (UTC)
Goto Top
thanks
strIP = DownloadString("http://192.168.2.101/ip.txt")
Msgbox strIP
open
Function DownloadString(strURL)
Dim objhttp
Set objhttp = CreateObject("Microsoft.XMLHTTP")
With objhttp
.Open "GET", strURL, False
.send
If .Status = 200 Then
DownloadString = .responseText
Else
DownloadString = ""
End If
End With
end function

function open
Dim objShell
set objShell = CreateObject("WScript.Shell")
objShell.run(strIP)
end function