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

    • Can’t say I’m a huge fan on first glance, but quite pleased it’s not too dramatic a departure from the current look.
    • Apple announces iOS 26 with Windows Vista-like 'Liquid Glass' redesign by Taras Buria At WWDC 2025, Apple announced iOS 26, a major software update with the biggest redesign since iOS 7 in 2013. With iOS 26 (other Apple-made operating systems now also carry the number 26 for more unified naming), Apple is introducing "Liquid Glass," a new material across the operating system, featuring Windows Vista-like glass material with translucency, reflections, light refraction, parallax, and more. Here is what Apple's senior VP of Software Engineering, Craig Federighi, said about the release: The redesigned UI is available on the Lock Screen and Home Screen, giving you more ways to personalize your iPhone and iPad. The Lock Screen can now generate a 3D effect for your photos and keep the most interesting parts of them as you receive notifications. With iOS 26, Apple is introducing new Apple Intelligence capabilities like Live Translation in iMessage, FaceTime, and Phone, allowing users to communicate across languages and translate text on the fly. You can also ask ChatGPT questions about what is happening on the screen, and Genmoji can mix your favorite emojis. Apple also redesigned the Phone app with a new UI and Call Screening feature, which eliminates interruptions by gathering information from the caller to let the user decide if they want to pick up the call. iMessage can filter out messages from unknown callers, set backgrounds for your chats, add polls, and display typing indicators in group chats. Apple Music now features Lyric Translations so you can understand music in foreign languages, and Lyrics Pronunciations will help you sing along regardless of language. Additionally, iOS 26 features a new Apple Games app, a single place for all your games, improved parental controls, new accessibility features, and more. You can read more about iOS 26 in the official announcement post on Apple Newsroom.
    • Just my personal opinion but if that's the way you've listed it, that may be the problem. Put the CPU , graphics card, ram and storage in that order, rest most people don't care or know about 
  • Recent Achievements

    • Rookie
      CHUNWEI went up a rank
      Rookie
    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
    • Week One Done
      VicByrd earned a badge
      Week One Done
    • Reacting Well
      NeoToad777 earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      476
    2. 2
      +FloatingFatMan
      279
    3. 3
      ATLien_0
      255
    4. 4
      Edouard
      204
    5. 5
      snowy owl
      201
  • Tell a friend

    Love Neowin? Tell a friend!