1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Batch file that will put current IP in a text file

Discussion in 'Windows XP' started by computer_pet, Nov 5, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. computer_pet

    computer_pet Thread Starter

    Joined:
    Jun 22, 2003
    Messages:
    484
    Hi,

    I need some kind of program/batch file that will place the current IP address (I have dynamic so it changes every two hours) in a text file that I have specified. The text file would have to be in this way:
    ie:
    I am using graburl to update my host of my location, so I thou ht that I could use graburl to do something like this. If it is not possible to include date and time in the text file it is not completely required. However the latest IP address would have to be at the top of the list not at the bottom (This must also happen even if date and time columns are in the list).

    Any help would be great.
    Cheers
     
  2. computer_pet

    computer_pet Thread Starter

    Joined:
    Jun 22, 2003
    Messages:
    484
    Any help :)
     
  3. Bob Cerelli

    Bob Cerelli

    Joined:
    Nov 2, 2002
    Messages:
    22,468
    Not sure how to get it all on one line.

    But if that's not too much of a concern, you could run something like:

    Echo ------------------------ > c:\ip.txt
    Echo | more | date | find "current" >> c:\ip.txt
    Echo | more | time | find "current" >> c:\ip.txt
    IPCONFIG | find "IP Address" >> c:\ip.txt
    Echo ------------------------->> c:\ip.txt
     
  4. computer_pet

    computer_pet Thread Starter

    Joined:
    Jun 22, 2003
    Messages:
    484
    I do not know how to do that and there is also the issue that I am through a firewall. So when I do ipconfig my ip address is 192.168.1.2
     
  5. computer_pet

    computer_pet Thread Starter

    Joined:
    Jun 22, 2003
    Messages:
    484
  6. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
    Why not use a service like DynDNS to maintain a public URL with your current IP address continually updated? That's how I run host processes.
     
  7. drdrew1469

    drdrew1469

    Joined:
    Nov 30, 2000
    Messages:
    436
    Sorry about opening an old(er) thread, but I was feeling in a "batch file mood" today :) I handle this one of two ways and use a command line smtp mailer scheduled with task scheduler to mail me whenever I want it.

    This gives me everything about my home network and current internet ip.
    -------------
    @echo off
    ipconfig /all >C:\Docume~1\yourname\Desktop\MyIP.txt
    bmail -s out.isp.net -p 25 -t [email protected] -f [email protected] -m "C:\Documents and Settings\yourname\Desktop\MyIP.txt" -h -a "MyIP"
    -------------

    This strips out all of the unneeded info and just send me my current internet ip.
    -------------
    @echo off
    for /f "tokens=2* delims=:" %%a in ('ipconfig ^| find "IP Address"') do set ip=%%a
    set ip=%ip: =%
    bmail -s out.isp.net -p 25 -t [email protected] -f [email protected] -b "%ip%" -h -a "MyIP"
    -------------

    I prefer the latter as the email I receive is much cleaner, but the first one is very helpful if you need all the info. bmail is free and can be found very easily or just ask me for it.

    hth,

    drew
     
  8. computer_pet

    computer_pet Thread Starter

    Joined:
    Jun 22, 2003
    Messages:
    484
    I downloaded bmail from the first site off google, I ran it a install program came up then "16bit Windows Subsystem; C:\windows\system32\autoexec.nt. The system file is not sutiable for running MS-DOS and Microsoft Windows applications. Choose 'close' to terminate the application."
    I pasted the seccond bit of code you gave into notepad and saved as a .bat file (I changed the email addreses). Ran it nothing happened, just a very quick flash of a windowed DOS screen.
    What did I do wrong?
     
  9. computer_pet

    computer_pet Thread Starter

    Joined:
    Jun 22, 2003
    Messages:
    484
    I found this php file that goes to your DSL router and finds your IP from there, It works for my RTA300. Code is below.
    NOTE: For this to work you need to have PHP installed and Apache Http server (or similar http server).

    Code:
    <?PHP
    #version 0.02b 07/04/2003
    # get-ip2 was originally written for a Dynalink RTA300W but the router died, It was then replaced
    # and the wireless part of the router was faulty so I gave up and reconfigured it for use with an
    # Alcatel Speedtouch Home that was upgraded to a Pro.
    # It should work on most ADSL Routers providing there is a page that lists the remote IP on its own.
    # Further modification may be made to this script however if you make any modifications please send
    # me a copy ( send any updates or changes to [email protected] )
    # the script can be setup as a cron job and called via wget or lynx. Its up to you how
    # often you want it to refresh but I'm intending to have it refresh every minute.
    
    # This scipt is copywrite (C) of Andrew Hooper 2003 [email protected]
    
    # Use it at your own rist, I take no responsibility problems the script my introduce or security holes.
    
    $stat_file = 'remote_ip'; # Name of the status file (apache must have write permissions in the directory)
    $log_file = 'dynamic_ip.log'; # log the history to this file
    
    $DSL_Username = 'user'; # ADSL Router Username
    $DSL_Password = 'pass'; # ADSL Router Password
    $DSL_Address = 'http://192.168.1.1:60/easystart.html'; #U RL on the router that displays the remote IP
    
    $IP_Update_URL[] = 'http://192.168.1.1:60/easystart.html'; # URL to open for updating the IP
    
    $debug = 'ON'; #Debuging ON / OFF
    
    ##################################################################
    ## You should not need to edit beyond this point ##
    ##################################################################
    
    if(ereg('(http:\/\/)(.*)',$DSL_Address,$DSL_regs)){
    
    if(!$DSL_Username && !$DSL_Password){
    $DSL_url = $DSL_regs[1] . $DSL_regs[2]; # If there is no Username and Password
    }else{
    $DSL_url = $DSL_regs[1] . $DSL_Username . ":" . $DSL_Password . "@" . $DSL_regs[2]; # if there is a Username and Password
    }
    
    $DSL_Status = implode('',file($DSL_url));
    $DSL_Status = strip_tags($DSL_Status, '');
    
    $ipok = 0;
    
    if(ereg('([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})',$DSL_Status,$IP_regs)){
    for($i=1; $i < 5; $i++){
    $ip_segment[$i] = intval($IP_regs[$i]);
    
    if($ip_segment[$i] <= 255) $ipok++;
    }
    $ip = implode(".", $ip_segment);
    }
    }
    
    $lastIP_Status = implode('',file($stat_file));
    
    if(ereg('([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})',$lastIP_Status,$lastIP_regs)){
    
    if($debug='ON'){echo "Last IP was : " . $lastIP_regs[0] . "<br>\n\r";}
    
    $last_IP = $lastIP_regs[0];
    }
    
    if($ip == $last_IP){
    if($debug='ON'){echo "No change to IP : " . $ip ."<br>\n\r";}
    }else{
    # Create or Alter the status file.
    if($debug='ON'){echo "Changing IP from : " . $last_IP . " to : " . $ip . "<br>\n\r";}
    $fname = $stat_file;
    $fp = fopen($fname,'w+');
    $log_ip = $ip . " Date: " . date("F j, Y, g:i a") . "\n\r";
    fwrite($fp,$log_ip);
    fclose($fp);
    
    $fname = $log_file;
    $fp = fopen($fname,'a');
    
    while(list($key, $val) = each($IP_Update_URL)){
    $dynamic_update = implode('',file($val));
    # Create and or write to the log file.
    $log_ip = "Date: " . date("F j, Y, g:i a") . " - Response :" . $dynamic_update . "\n\r";
    if($debug='ON'){echo $dynamic_update . "<br>\n\r";}
    }
    fwrite($fp,$log_ip);
    fclose($fp);
    
    }
    
    
    ?> 
     
  10. drdrew1469

    drdrew1469

    Joined:
    Nov 30, 2000
    Messages:
    436
    It would be the bmail from this site: http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm The first one google returns is a bulk email software package. Unless you put this bmail is a directory defined by your environmental variables, you will need to reference a path. I use this all the time (everyday) and once it's setup properly it runs flawlessly.

    hth,

    drew
     
  11. computer_pet

    computer_pet Thread Starter

    Joined:
    Jun 22, 2003
    Messages:
    484
    Thanks,
    will try out now :)
     
  12. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/292941

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice