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

    • The new official logo of the GOP
    • Linux 6.16-rc1 is out: What's new and what does it mean for your system? by Paul Hill Linus Torvalds, head and founder of the Linux kernel, has announced the closure of the merge window where major new features are added to the kernel, and the beginning of the Linux 6.16 release candidates, beginning with release candidate 1 (Linux 6.16-rc1). Linux 6.15 was released two weeks ago and in the time since, developers have had the opportunity to try and get their new kernel features into the Linux 6.16 kernel. Over the next two months, we will get seven or eight release candidates where developers will stabilize new and existing features. This means that the stable version of Linux 6.16 will arrive around the end of July. Torvalds said that the merge window seemed pretty normal this time, but did say he had a feeling that there were more “late straggler” pull requests than is typical. Despite this, everything seems to be fine and the schedule will be going forward as planned. Key areas of development Torvalds explained that around half of the changes in the first release candidate were driver updates, with the bulk of those being made up with by GPU and networking drivers. For end users these are the most important changes because when your favorite distribution of Linux ships a new release with this kernel, it will support more graphics cards and networking equipment like Wi-Fi cards. The non-driver updates in this version are split between architecture-specific updates, documentation and tooling (perf tool and selftests), and core changes to filesystems, core kernel, memory management, and networking. Torvalds said the core changes include some of the “most important” changes, though they’re not necessarily major changes. Fixes to the core ensure a more stable Linux kernel for end users, plus better performance. The merge window saw developers submit thousands of non-merge commits and merges. The non-merge commits were around 13,000 while the merge commits nearly reached 1,000. There were 1,783 unique authors submitting code during this window. Next steps Over the coming weeks, Linux developers, including individuals or representatives of companies, will submit bug fixes for new and existing features. This release candidate cycle will run until around the end of July and then the final version will become available. End users shouldn’t go out and download Linux 6.16 when it’s released, instead just wait for your Linux distribution to update to it, as distribution-specific changes get made. Neowin will be following these releases and reporting on any interested changes that are noted. Source: LKML
    • There was no cancelation. Microsoft delayed work on it to focus on further tuning the OS and improving the OS experience overall, before going full core into a direct hardware battle with their partners.
    • As someone who has 500+ hours of playtime on Anno 1800, all I can say is shut up and take my money.
  • Recent Achievements

    • Week One Done
      MadMung0 earned a badge
      Week One Done
    • Reacting Well
      BlakeBringer earned a badge
      Reacting Well
    • Reacting Well
      Lazy_Placeholder earned a badge
      Reacting Well
    • Dedicated
      Epaminombas earned a badge
      Dedicated
    • Veteran
      Yonah went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      469
    2. 2
      +FloatingFatMan
      273
    3. 3
      ATLien_0
      242
    4. 4
      snowy owl
      210
    5. 5
      Edouard
      182
  • Tell a friend

    Love Neowin? Tell a friend!