0

I've made a bat file to get my public ip and write it into a txt file; powershell -Command "curl icanhazip.com > PATH/output.txt" powershell -Command "Start-Sleep -s 1" powershell -Command "(Get-Content PATH/output.txt)[4] > PATH/ip.txt"

First line gets bunch of info which contains my public ip at the fourth line of the output file. Third line gets fourth line from the output file and writes it to another. Then I'm left with this:

Content           : xxx.xxx.xxx.xxx

I want to extract only the ip. In other words I want to remove

Content           : 

from the text file. This part doesn't change and has constant character count. Maybe there is a code for deleting this many characters from the start of the text? I couldn't find such command.

How can I do that without using anything other than bat file and powershell commands. I wanna be able to get this all in one bat file. (I don't understand vbs and it scares me.)

Shoot your ideas at me please. Thanks in advance. :)

0
1

Using (curl icanhazip.com).Content will return only the IP address:

PS C:\> (curl icanhazip.com).Content
xx.xx.xx.xx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.