Write just my current IP address to a text file?


Recommended Posts

If there a way in Linux to output my current IP address to a text file?

ifconfig displays the IP address and I could redirect the output to a file but then I'd have to strip the junk. Is there a direct way to only write the current ip address?

Edit:

What I would really ultimately like to write would be:

dnscmd /recorddelete mydomain.ca ns2 a /f
dnscmd /recordadd mydomain.ca ns2 a xxx.xxx.xx.xxx

(where xxx.xxx.xxx.xxx = my current IP address)

  Quote
I'd like to have a text file that contained nothing other than "xxx.xxx.xxx.xxx"

I know there's plenty of guys on here with nothing buy XXX files. Surely you could borrow some?

Other than that, I can't think of a way to really do what you're asking. I'll poke around a bit.

Edited by SFalcon

dnscmd /recordadd mydomain.ca ns2 a `/sbin/ifconfig eth0 | grep addr | awk '{ print $2 }' | sed -e 's/addr://'`

...replacing eth0 with your external interface.

EDIT: This doesn't drop it to a text file, though... do you need that?

  rezza said:
dnscmd /recordadd mydomain.ca ns2 a `/sbin/ifconfig eth0 | grep addr | awk '{ print $2 }' | sed -e 's/addr://'`

...replacing eth0 with your external interface.

EDIT: This doesn't drop it to a text file, though... do you need that?

586169993[/snapback]

That should be:

/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/addr://'

Otherwise, it might pick up your IPv6 line too.

  code_monkey said:
That should be:

/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/addr://'

Otherwise, it might pick up your IPv6 line too.

586170058[/snapback]

True, I forgot about IPv6 because I don't use it... good point ;)

  code_monkey said:
That should be:

/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/addr://'

Otherwise, it might pick up your IPv6 line too.

586170058[/snapback]

You boys are fancy.

It looks like you are taking the verbose output from ifconfig and cleaning it.

Yea, I need to output it to a text file with a .CMD extension.

I want to write it to a SAMBA drive and then execute it as a batch file on a Windows Server box.

Basically I am trying to write my Linux IP address to the DNS service on my Windows box. Unfortunately, I am still much better with Windows.

I've been having a TERRIBLE time getting iptables/ipchains to forward traffic from the Linux box to the Windows box. However, I just found rinetd and I am again re-envigorated in my quest to have them work together properly.

  fred666 said:
You boys are fancy.

It looks like you are taking the verbose output from ifconfig and cleaning it.

Yea, I need to output it to a text file with a .CMD extension.

I want to write it to a SAMBA drive and then execute it as a batch file on a Windows Server box.

Basically I am trying to write my Linux IP address to the DNS service on my Windows box.  Unfortunately, I am still much better with Windows.

I've been having a TERRIBLE time getting iptables/ipchains to forward traffic from the Linux box to the Windows box.  However, I just found rinetd and I am again re-envigorated in my quest to have them work together properly.

586170485[/snapback]

ip=$(/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/addr://')
echo "dnscmd /recorddelete mydomain.ca ns2 a /f" > something.CMD
echo "dnscmd /recordadd mydomain.ca ns2 a $ip" >> something.CMD

  BudMan said:
Um dude - Why not just make it a static entry in your windows dns?? Where is the linux box getting its IP address from? Your dhcp?? Your ISP?

586171034[/snapback]

It's a dynamic IP from a backup internet provider.

I used to have a working solution when I had two Windows boxes.

The remaining Windows box has the static IP.

  rezza said:
ip=$(/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/addr://')
echo "dnscmd /recorddelete mydomain.ca ns2 a /f" > something.CMD
echo "dnscmd /recordadd mydomain.ca ns2 a $ip" >> something.CMD

586171084[/snapback]

Thank you rezza. That looks perfect.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • That has AI shoved in as well, and I expect at some point that will become more in your face.
    • Edge on a Mac? Hell no, as bad as Edge on Linux, I did not use Edge on Windows. The Ai rubbish is getting too much, seem like it is being put into every flipping app and devices these days. I have disabled it on my Mac, dead easy to do that, disabled it on Brave. I agree with David Uzondu, why can't browsers be simple like they used to be. Not that Chrome is simple and still have AI shoved into that. I like the Duck Duck go browser, but that have AI even, but it can be disabled, the only problem with the Duck Duck go browser is no support for extensions. Maybe we should back to Mosaic.
    • Another reason to stick with Firefox
    • Yes, the Control Pannel issue has been fixed. As I ask when people claim it hasn't, can you name a single thing in Windows 11 that can only be done by opening Control Panel? Your comment about Error 0x80070643 is so asinine that I debated if you were worth a reply, but here I am. The article mentioned a VERY specific issue with the WinRE partition size being too small in Windows 10 and preventing updates from being installed unless you reinstalled or manually fixed it. That issue does not exist on Windows 11, period. To point to random issues with Windows updates on 11 that don't affect everyone and don't involve that issue is being dishonest. Had the article said "Issues with updates, such as..." then I'd agree with you, but it didn't, it simply mentioned that one specific issue, which despite your claim, does not exist on 11 or on newer builds of 10 (so the article is kind of wrong, it did get fixed, just not gracefully). As far as UX/UI comes more down to opinion, but again, you are saying it is "terrible" which has nothing to do with consistency. Windows 11 has a more consistent interface. You are welcome to say it is constantly bad, but I don't see how any objective person can say it isn't more constant than Windows 10's unholy merger of Windows 7 and Windows 8. To be fair, I really like Windows 10's interface, it worked great, but was it consistent, NO, it was one of the least consistent interfaces MS has ever made. I agree with the lack of competition. Linux continues to get better
  • Recent Achievements

    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
    • One Month Later
      James_kobe earned a badge
      One Month Later
    • Week One Done
      James_kobe earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      671
    2. 2
      ATLien_0
      256
    3. 3
      Xenon
      165
    4. 4
      neufuse
      145
    5. 5
      +FloatingFatMan
      114
  • Tell a friend

    Love Neowin? Tell a friend!