Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write ip address to text file

Status
Not open for further replies.

eja2000

Programmer
Nov 30, 2003
209
NG
hello alll,
i need a script that will write an ip address to text file.
can anyone help?
thanks.
 
Do a keyword search in this forum for IPEnabled

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
first you need to look at

FileSystemObject.CreateTextFile method

Then you need to determine the ipaddress
use the forum search facil. and try

Winsock or WMI and ipaddress
 
not that i would go this way myself but....

WshShell.Run("cmd /c ipconfig > c:\ipaddress.txt")

or something like that
 
its the ip address of the pc the script is running it on that i want to write to txt file.
 
what are your requirements for the text file? where will it be located?
what information do you want to write to the text file? do you mind having the extra bits that an ipconfig at a command prompt will give you?
 
Set WshSock = WScript.CreateObject("MSWinsock.Winsock")
strIPAddress = WshSock.LocalIP
Msgbox strIPAddress
Set WshSock = Nothing

'or

strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.IPAddress) Then
msgIP = msgIP & vbCrLf & "IP address of " & Trim(objAdapter.Description) & " is "
For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
msgIP = msgIP & objAdapter.IPAddress(i) & " "
Next
End If
Next

'have a search for OpenTextFile in the key word search try and put something together then post back with how far youve got and someone can give you a hand
 
i want to simply write the ip address of my computer to a hardcode text file (already existing on my PC) on my computer when i click a .vbs file located somewhere on my PC.
Thanks
 
i wrote the following but the file gets created but no ip address is written to it..
any suggestions??
thanks
-----------------------------------
set fil = wscript.CreateObject("scripting.filesystemobject")

set txt = fil.opentextfile("c:\xxx\ip_address.txt", 8, true)

txt =Request.ServerVariables("LOCAL_ADDR")

txt.writeline(txt)

txt.close

'wscript.echo "done
 
Working from mrmovie's script I added a line to output the IP address. If you don't want the description of the network card, then comment out this line:

msgIP = msgIP & vbCrLf & "IP address of " & Trim(objAdapter.Description) & " is "

Here is the script, just copy into a text file and name it .vbs and you're ready to go.

strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\xxx\ip_address.txt", 8, True)

Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.IPAddress) Then
msgIP = msgIP & vbCrLf & "IP address of " & Trim(objAdapter.Description) & " is "
For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
msgIP = msgIP & objAdapter.IPAddress(i) & " "
objTextFile.WriteLine(msgIP)

Next
End If
Next
 
Hello eja2000,

[1] >>txt =Request.ServerVariables("LOCAL_ADDR")
Request object is for asp application. (I then suppose it is?)

[2] You assign txt one to textfile object and then to a string. Hence, error?!... Change the name one way or the other.
[tt]
set [red]o[/red]txt = fil.opentextfile("c:\xxx\ip_address.txt", 8, true)
txt =Request.ServerVariables("LOCAL_ADDR")
[red]o[/red]txt.writeline(txt)
[red]o[/red]txt.close
[/tt]
regards - tsuji
 
mrmovie,

Someone has not asked you not to typing too loud?...

- tsuji
 
yeah im on a wise package studio course and the guy next to me couldnt concentrate ;-) must have his own private office at work, lol
 
mrmovie, okay, keep it up. I'm not going to stay awake for long today. Am calling the day. - tsuji
 
Let me know what you think of Wise. We are looking at the complete package to handle our IT Relaease Management Process including packaging of course. I have used Wise extensively to create and modify MSIs, but I haven't used any of the process management pieces.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top