Join INGunOwners For Free
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
  1. #1
    Grandmaster Cameramonkey's Avatar

    User Info Menu

    Any powershell scripters in the house?

    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.
    Quote Originally Posted by Kirk Freeman View Post
    A confused cop is an arresty cop.
    Quote Originally Posted by hoosierdoc View Post
    also, where do we sign up to touch Frank's equipment?

  2. #2
    Expert jkaetz's Avatar

    User Info Menu

    I see two potential options:
    Code:
    $uri = "https://directnic.com/dns/gateway/[the secret string they provide]/?data=$wanip"
    Invoke-WebRequest -uri $uri
    And if that works, you might be able to use the below if you want it inline

    Code:
    Invoke-WebRequest -uri ("https://directnic.com/dns/gateway/[the secret string they provide]/?data=$wanip)"
    Powershell may not be evaluating the string before sending it to Invoke-WebRequest

  3. #3
    Grandmaster HoughMade's Avatar

    User Info Menu

    Geez...this is just like talking to my son.
    ​Bullies suck. They also make you stronger.

  4. #4
    Master fullmetaljesus's Avatar

    User Info Menu

    Quote Originally Posted by jkaetz View Post
    I see two potential options:
    Code:
    $uri = "https://directnic.com/dns/gateway/[the secret string they provide]/?data=$wanip"
    Invoke-WebRequest -uri $uri
    And if that works, you might be able to use the below if you want it inline

    Code:
    Invoke-WebRequest -uri ("https://directnic.com/dns/gateway/[the secret string they provide]/?data=$wanip)"
    Powershell may not be evaluating the string before sending it to Invoke-WebRequest
    Personally I'd go with ith the first option here.

    In the future when that string changes or url changes it will be easier to up date a variable be updating the actual code.

  5. #5
    Grandmaster Cameramonkey's Avatar

    User Info Menu

    Second option doesnít work. It sends the literal string of the variable name as typed, and doesnít substitute the variable. Iíll try the first option later tonight.
    Quote Originally Posted by Kirk Freeman View Post
    A confused cop is an arresty cop.
    Quote Originally Posted by hoosierdoc View Post
    also, where do we sign up to touch Frank's equipment?

  6. #6
    Grandmaster DoggyDaddy's Avatar

    User Info Menu

    Quote Originally Posted by HoughMade View Post
    Geez...this is just like talking to my son.
    That's why I just stick to COBOL. At least it looks somewhat like English.

  7. #7
    Grandmaster Cameramonkey's Avatar

    User Info Menu

    First option worked like a charm. Thanks!

    Apparently you have to store it to get it to honor the variable.

    Somebody give Jkaets max rep for me. Board sez I gotta spread it around.
    Quote Originally Posted by Kirk Freeman View Post
    A confused cop is an arresty cop.
    Quote Originally Posted by hoosierdoc View Post
    also, where do we sign up to touch Frank's equipment?

  8. #8
    Grandmaster WebSnyper's Avatar

    User Info Menu

    Quote Originally Posted by Cameramonkey View Post
    First option worked like a charm. Thanks!

    Apparently you have to store it to get it to honor the variable.

    Somebody give Jkaets max rep for me. Board sez I gotta spread it around.
    Got him for you.
    Quote Originally Posted by Frank_N_Stein
    I am trying to turn every thread I involve myself in into a **** show.

  9. #9
    Grandmaster Cameramonkey's Avatar

    User Info Menu

    And is there anything INGO CANT help with?
    Quote Originally Posted by Kirk Freeman View Post
    A confused cop is an arresty cop.
    Quote Originally Posted by hoosierdoc View Post
    also, where do we sign up to touch Frank's equipment?

  10. #10
    Expert jkaetz's Avatar

    User Info Menu

    Quote Originally Posted by Cameramonkey View Post
    And is there anything INGO CANT help with?
    A winning lotto number generator.

    I also just noticed my 2nd example has the closing paren inside the double quote, it should be outside. I'm somewhat surprised that didn't work though. I've run into more than a few instances where I had to force PS to evaluate a string before giving it to a cmdlet.


Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Button Dodge