I'm ><THIS close to finishing a 2 part script to fix a problem, but I just cant quite get there. I'm having trouble picking up a variable I created.
I need to start using the Dynamic DNS feature that Directnic offers. Frankly its a little lacking because they dont offer an app or router integration like others do. (But its free) They just give me a hard coded URL to visit, and when I hit the web server it updates the DNS entry. But I have to know what IP address to feed it. Now I'm trying to automate it so it can be scripted.
Step 1: Get the IP address
(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content | Tee-Object -Variable wanip
That works and when I "echo $wanip" it outputs the correct IP address from step 1. So I know that part works.
Step 2: Push the new address to Directnic
I'm supposed to visit this URL: https://directnic.com/dns/gateway/[the secret string they provide]/?data=1.2.3.4 (with 1.2.3.4 the address I want to change the DNS entry to)
So I send this command and it works:
(Invoke-WebRequest -uri "https://directnic.com/dns/gateway/[the secret string they provide]/?data=1.2.3.4")
But if I try this command, it sends the literal value $wanip not the stored string.
(Invoke-WebRequest -uri "https://directnic.com/dns/gateway/[the secret string they provide]/?data=$wanip")
So what am I missing? How do I get it to actually send the variable not the variable name?
Eventually this will run regularly as a script to keep that IP updated.
I need to start using the Dynamic DNS feature that Directnic offers. Frankly its a little lacking because they dont offer an app or router integration like others do. (But its free) They just give me a hard coded URL to visit, and when I hit the web server it updates the DNS entry. But I have to know what IP address to feed it. Now I'm trying to automate it so it can be scripted.
Step 1: Get the IP address
(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content | Tee-Object -Variable wanip
That works and when I "echo $wanip" it outputs the correct IP address from step 1. So I know that part works.
Step 2: Push the new address to Directnic
I'm supposed to visit this URL: https://directnic.com/dns/gateway/[the secret string they provide]/?data=1.2.3.4 (with 1.2.3.4 the address I want to change the DNS entry to)
So I send this command and it works:
(Invoke-WebRequest -uri "https://directnic.com/dns/gateway/[the secret string they provide]/?data=1.2.3.4")
But if I try this command, it sends the literal value $wanip not the stored string.
(Invoke-WebRequest -uri "https://directnic.com/dns/gateway/[the secret string they provide]/?data=$wanip")
So what am I missing? How do I get it to actually send the variable not the variable name?
Eventually this will run regularly as a script to keep that IP updated.