Rawns Posted August 31, 2012 Posted August 31, 2012 (edited) Got a network at home and I'm after a clever way of getting my 'master' IP address and storing it in a text file. Basically, I run a L4D2 dedicated server and to get it visible, I need to have the IP address in the start up file, however I don't have a static IP. I was hoping to some how get my main IP into a text file so I could create a batch file to start the server and pull in the current IP. I could then create a couple of batch files and scheduled tasks to restart the server every 12 or 24 hours ensuring the server starts with the latest IP address. Would save me having to do it manually! Edit: I do use DynDNS however the cvar command in the startup is +net_public_adr and it only seems to be happy with an IP rather then domain name... Edited August 31, 2012 by Rawns
mac_shinobi Posted August 31, 2012 Posted August 31, 2012 (edited) bat file to pipe and find ? ipconfig /all | Find "IPv4">c:\ipaddy.txt In a bat file ? vbscript : Dim colIPResults, objFile, objFSO, objNIC, objWMI, objWSHNetwork, strAddresses, strIPAddress, strWQL, strComp Const FOR_APPENDING = 8 Sub DestroyObjects() If IsObject(objFile) Then Set objFile = Nothing If IsObject(objFSO) Then Set objFSO = Nothing If IsObject(objWMI) Then Set objWMI = Nothing If IsObject(objWSHNetwork) Then Set objWSHNetwork = Nothing ' If IsObject() Then Set = Nothing End Sub Set objFSO = CreateObject("Scripting.FileSystemObject") Set objWSHNetwork = CreateObject("WScript.Network") Set objWMI = GetObject("WinMGMTS:root\cimv2") strWQL = "SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'" Set colIPResults = objWMI.ExecQuery(strWQL) For Each objNIC In colIPResults For Each strIPAddress in objNIC.IPAddress If strAddresses = "" Then strAddresses = strIPAddress Else strAddresses = strAddresses End If Next Next strComp = objWSHNetwork.ComputerName If strAddresses ="0.0.0.0" Or strAddresses ="" or strAddresses = "undefined" Then msgbox ("No Connection Detected") Else msgbox "Network Address - " & strAddresses & vbcrlf & "Computer Name - " & strComp End If DestroyObjects() Edited August 31, 2012 by mac_shinobi 1
Rawns Posted August 31, 2012 Author Posted August 31, 2012 bat file to pipe and find ? ipconfig /all | Find "IPv4">c:\ipaddy.txt In a bat file ? It returns my LAN address 192.168.0.3 rather then the IP from my ISP.
mac_shinobi Posted August 31, 2012 Posted August 31, 2012 It returns my LAN address 192.168.0.3 rather then the IP from my ISP. oh - sorry. There is a way but would have to dabble about a bit
Arthur Posted August 31, 2012 Posted August 31, 2012 (edited) Here are a couple of ways... IP.cmd @echo off cd /d "%~dp0" curl -s http://slurpware.org/ > ip.txt ^ CURL for Windows can be downloaded from here. IP.ps1 (New-Object System.Net.WebClient).DownloadString("http://slurpware.org") or (New-Object System.Net.WebClient).DownloadString("http://checkip.dyndns.org") -replace "[^\d\.]" With PowerShell you could write the IP directly to your L4D2 startup file. I don't have the dedicated server installed myself, so I am unable to test. Edited August 31, 2012 by Arthur 2
mac_shinobi Posted August 31, 2012 Posted August 31, 2012 Last comment from here : How to get my external IP address (over NAT) from the Windows command-line? - Super User Then just a case of writing the output of this to a text file which is easy enough : DevGuru VBScript Method: FileSystemObject.CreateTextFile Combined Code : dim filesys, filetxt, getname, path Set filesys = CreateObject("Scripting.FileSystemObject") Set filetxt = filesys.CreateTextFile("c:\ip to txt\somefile.txt", True) path = filesys.GetAbsolutePathName("c:\ip to txt\somefile.txt") getname = filesys.GetFileName(path) filetxt.WriteLine WAN_IP() filetxt.Close wscript.echo WAN_IP() function WAN_IP() set obj = createobject("Microsoft.XMLHTTP") call obj.open("get", "http://ifconfig.me/ip", false) obj.send() strresponse = obj.responsetext set obj = nothing if strresponse <> "" then strIP = strresponse else strIP = "Unavailable" end if WAN_IP = trim(strIP) end function You would need to edit lines 3 and 4 to make it create the text file in the relevant path and name the text file something a bit better than somefile.txt I think the 4th line is just to get the path and getname etc you may not need so you could probably delete those lines 1
Rawns Posted August 31, 2012 Author Posted August 31, 2012 Thanks both. That's worked a treat. I'd +rep but for some reason, the box is not loading properly... :S 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now