What is the fastest way to know my IP address from the command line?

Log In to Reply

Curiosity Technology Computers and Smartphones What is the fastest way to know my IP address from the command line?

  • I have a connection that assigns me a dynamic IP address for every session on our network. Sometimes the IP changes so often for every router reboots. I usually google ‘my ip’ for this. Is there a faster and a better way to get the ip address? It would be nice if anyone could get a command line based solution for this. Unfortunately, ipconfig won’t return the public IP.

  • I don’t think there is a faster way in Windows (If that’s what you are asking for). You can either install cURL on Windows and do a simple thing like this curl ipinfo.io. If your machine is Linux, I think it’s pre-installed and you can get your IP right from the terminal.

    However, you can write up a vb script in Windows that will show you your public IP as a response from a server. Maybe the following script would help you.

    Dim http : Set http = CreateObject( "MSXML2.ServerXmlHttp" )
    http.Open "GET", "http://icanhazip.com"
    http.Send
    Dim ipbox
    ipbox = InputBox("Your Public IP",,http.responseText)

    Save it as myip.vbs in your desktop for quick access. You could also run it from CLI using this command – cscript myip.vbs

  • I also tried to do this with Python. I found out that ipinfo.io returns a JSON object for any requests. If you have Python installed in your Windows machine, maybe this will help you display your public IP address in the command line.

    import requests
    import json
    
    r = requests.get('http://ipinfo.io/')
    json_data = r.json()
    
    print json_data['ip']

    If you want to copy the IP to your clipboard, all you have to do is to use the | clip operator. E.g: python ip.py | clip

    Pretty simple. :)

    Additionally, you can add a batch file to get it done quickly!

    @echo off
    echo Your Public IP
    python ipfind.py
    set /P choice = "Do you want to copy it to your clipboard [type 'y' or terminate using 'CTRL+C'] ? "
    if "%choice%" == "y" goto copy_stuff_to_clipboard
    :copy_stuff_to_clipboard
    python ipfind.py | clip
    pause

You must be logged in to reply to this topic. Log In