#1
  1. Retired
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Finland
    Posts
    9,143
    Rep Power
    2493

    Get IP address and write to file


    Hi guys.

    I am trying to get the IP address of my home computer, *DSL connection, then write that address to a text file.

    I have used ipconfig and that spurts out loads of information - I only want the 127.0.0.1 (except not that one, my actual IP).

    Then to write it all to a file. I am looking to do this through DOS prompt so I can add it to a .bat file I have already made.

    I am trying not to use any other software (I have accomplished what I want with wget, but I would rather do it with no external applications).

    Hope someone can help.

    Thanks in advance...

    Jamie

    Cheers,
    Jamie

    >_ skiFFie ? | Twitter

    __________________

    Let the might of your compassion arise to bring a quick end
    to the flowing stream of the blood and tears .....
    Please hear my anguished words of truth.

    __________________
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    itīs a hard way without connecting to the internet.

    one pc can have several NICs. each NIC has its own IP, each could be connected to the Internet or parts of it.

    to find the IP that connects to the internet is (nearly) impossible if eg. a router is in between.

    Once you connect to the internet, you are part of it, you cannot say, "the internet is behind my modem" - the internet is around you. So you cannot tell behind which IP/NIC the internet is either...

    if you only want to use the software yourself, you can use ifconfig and filter the 127.0.0.1. you should watch the output of ifconfig and use line numbers to get the IP.

    For giving the software to others whose configuration you donīt know, you cannot do it reliably at all!

    Question: what do you need your own IP for?
  4. #3
  5. Retired
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Finland
    Posts
    9,143
    Rep Power
    2493
    Hi,

    I am doing a dynamic DNS type thing.

    I have a sub-domain on my "real" web server to redirect to my PC's server if it is online.

    This part is done with PHP, scanning ports etc. I also have page there that I can update my PC's IP address through a form, again PHP.

    What I am trying to do is run a script from my PC that updates the IP address of my PC.

    This I have accomplished through similar PHP script on my local machine, then FTPing the results to my "real" server.
    However, I am using a 3rd party software to accomplish this(wget), which I am trying to avoid.
    I was also trying to avoid PHP on my PC, strange though that may be(?)

    The IP that I get when using the form on webserver and local machine seems to be correct as the redirect works.

    Any ideas?

    Thanks

    J

    Cheers,
    Jamie

    >_ skiFFie ? | Twitter

    __________________

    Let the might of your compassion arise to bring a quick end
    to the flowing stream of the blood and tears .....
    Please hear my anguished words of truth.

    __________________
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    yes. as you need to connect to the internet anyway (ftp), you can get the IP there.

    setup the remote script to use the callerīs IP (in PHP/Apache: $HTTP_SERVER_VARS['CLIENT_ADDRESS'] iirc) for the DNS setup.
    then you donīt need to find out your own IP. as i told above, you could do it easily (parse ipconfigīs output), but never reliably.

    this way will always work.

    if you donīt want external programs, what do you call "intern"? if you use PHP on your client machine too, it is a simple:
    PHP Code:
    $f=file("http://www.your-server.com/updateip.php"); 
    and for the "updateip.php":
    PHP Code:
    $fp=fopen("ip.txt","w");
    fwrite($fp$HTTP_SERVER_VARS['CLIENT_ADDR']);
    fclose($fp); 

IMN logo majestic logo threadwatch logo seochat tools logo