Windows Batch - How to get the external IP into a batch-file variable

前端 未结 3 1660
臣服心动
臣服心动 2020-12-17 01:23

I am making a program that checks if a user\'s IP is a certain IP address.

Currently, I created a successful internal IP version:

@echo off
set userI         


        
3条回答
  •  有刺的猬
    2020-12-17 01:43

    To get your public IP without additional parsing do this:

    curl "http://api.ipify.org"

    EDIT:

    This version is more reliable across windows language versions:

    for /f "tokens=3 delims== " %%A in ('
    nslookup -debug myip.opendns.com. resolver1.opendns.com 2^>NUL^|findstr /C:"internet address"
    ') do set "ext_ip=%%A"
    

提交回复
热议问题