Browse Source

Add files via upload

master
Chase Hall 5 months ago
committed by GitHub
parent
commit
cb49e864c1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions
  1. +16
    -0
      Update-Public-IP.bat
  2. +49
    -0
      Update-Public-IP.py

+ 16
- 0
Update-Public-IP.bat View File

@ -0,0 +1,16 @@
:: Make this file a task schedule for 1 am or something.
@echo off
:: Grab my Public IP. Throw it in Documents\IP.txt.
C:\curl-7.69.1-win64-mingw\bin\curl.exe https://ip.chasehall.net/pub.php > %USERPROFILE%\Documents\IP.txt
:: Kill IW4MAdmin
taskkill /F /FI "WindowTitle eq IW4MAdmin" /T
:: Replace IW4MAdminSettings.json with our new IP.
python Update-Public-IP.py
:: Start IW4MAdmin Again
cd IW4MAdmin
set DOTNET_CLI_TELEMETRY_OPTOUT=1
echo y | dotnet Lib\IW4MAdmin.dll

+ 49
- 0
Update-Public-IP.py View File

@ -0,0 +1,49 @@
#!/usr/bin/env python3
# Make Update-Public-IP.bat a task schedule for 1 am or something.
#
# What: Replaces first key (and every instance after) in IW4MAdminSettings.json's "IPAddress"
# with whatever content is in Documents\IP.txt
#
# Example:
# "IPAddress": "123.456.789.123",
# into
# "IPAddress": "99.88.123.456",
#
#
# Variables, feel free to change me.
iw4madminconfig="C:\\IW4MAdmin\\Configuration\\IW4MAdminSettings.json" # IW4MAdmin Settings.
ipfile="C:\\Users\\user\\Documents\\IP.txt" # Should ONLY contain an IP. Example: 123.456.789.123
# Don't change unless you know what you're doing.
list=[]
myfile = open(iw4madminconfig, "rt")
contents = myfile.read()
ip1 = open(ipfile, "rt")
ip = ip1.read()
def lines_that_contain(string, fp):
return [line for line in fp if string in line]
with open(iw4madminconfig, "r") as fp:
for line in lines_that_contain("IPAddress", fp):
newline=line[20:]
newline2=newline[:(len(newline))-3]
break
reading_file = open(iw4madminconfig, "r")
new_file_content = ""
for line in reading_file:
stripped_line = line.strip()
new_line = stripped_line.replace(newline2, ip)
new_file_content += new_line +"\n"
reading_file.close()
writing_file = open(iw4madminconfig, "w")
writing_file.write(new_file_content)
writing_file.close()
myfile.close()
ip1.close()
fp.close()

Loading…
Cancel
Save