DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 2nd October 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Default Reliable method to get an IP?

OK I have a few pppoe connections... which can be viewed on the command line by `ifconfig pppoe0` `ifconfig pppoe1` and so on...

I was wondering what's the most reliable way to get the IP address of them?

They all have different dynamic IP and changes over time... I want a way to detect the changes...

I was thinking of writing a python script that parses the output of `ifconfig pppoeX` and grab the IP address, compare to the one if had before.

The python script would need to be run as a cron job... maybe every 10 minutes, or every hour.

Are there any better way to do this? in pf rules one can do something like (pppoe) which seems to be more "event driven", when the changes occur it notifies pf somehow...

If there are more effective way that is "event driven" like so that I don't need to run a cron job, I don't mind if it had to be written in C or something... as long as it exist...

Cheers.
__________________
She sells C shells by the seashore.
Reply With Quote
  #2   (View Single Post)  
Old 2nd October 2008
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

PF will automatically adjust rules if you place the interface within parentheses, and the IP address changes.

Tools for managing dynamic IP addresses are already in the ports/packages system. For example, I use net/ddclient to keep my DNS records up-to-date at dyndns.org.
Reply With Quote
  #3   (View Single Post)  
Old 2nd October 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Default

Yes I am using ddclient as of right now, as far as I can see it is using a web site to check its IP... this would work fine with one IP address, but it'll not work with multiple pppoe connections because there would be only one default gateway...

I notice that in the ddclient configuration that one can give it a nic name instead... I guess the question is that rather if it will work with BSD or if it assumes that it is on a Linux system and couldn't figure it out...
__________________
She sells C shells by the seashore.
Reply With Quote
  #4   (View Single Post)  
Old 2nd October 2008
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

Perhaps.

There are only two ways to check IP address assignments that I can think of:

1) Examining IP addresses in ifconfig output, as you have already suggested (there might be a sysctl too, but this is the same thing, really).
2) Connecting out and back, as ddclient does, because it is not operating system specific (as you have noted).

One could, I suppose, also check timestamps on /var/db/dhclient.leases.IFNAME; changing modification timestamps would show lease renewals or new address assignments. The content may also be examined for additional information, such as lease expirations.

Last edited by jggimi; 2nd October 2008 at 02:47 PM.
Reply With Quote
  #5   (View Single Post)  
Old 2nd October 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Default

Well, I have just look at closer look at ddclient.

It seems to be pretty flexible, I haven't tried this yet, but from the documentation on sourceforge, you can supply an interface name into it, which ddclient will in turn call ifconfig itself. It also seems like they have some smart regex text process build in that will parse the output of any ifconfig, rather on Linux or BSD, and search for something that looks like an IP address; additionally, you can specify a pattern which the search will only be perform after it.

A command can also be specified into ddclient, so you can write any script which can get the IP address from anywhere, and whatever it outputs ddclient will try to parse it and search for an IP... again it is the same as the specifying an interface name, one can supply a pattern which ddclient will skip in its search.

Got to try this out soon.
__________________
She sells C shells by the seashore.
Reply With Quote
  #6   (View Single Post)  
Old 3rd October 2008
darkmark darkmark is offline
-current abuser
 
Join Date: Oct 2008
Posts: 5
Default

You can use getifaddrs(3) if you want to do this programmatically.
__________________
darkmark
(!wired)?(coffee++):(wired);
Reply With Quote
  #7   (View Single Post)  
Old 3rd October 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Default

Ah, so getifaddrs(3) gets you a linked list of all interfaces on the system? Looks nice!
__________________
She sells C shells by the seashore.
Reply With Quote
  #8   (View Single Post)  
Old 3rd October 2008
darkmark darkmark is offline
-current abuser
 
Join Date: Oct 2008
Posts: 5
Default

Quote:
Originally Posted by Sunnz View Post
Ah, so getifaddrs(3) gets you a linked list of all interfaces on the system? Looks nice!
Yeah, see my blog entry here where I grab the MAC address, but the ip address shouldn't be much different.

http://othermark.livejournal.com/3005.html
__________________
darkmark
(!wired)?(coffee++):(wired);
Reply With Quote
  #9   (View Single Post)  
Old 3rd October 2008
Sunnz's Avatar
Sunnz Sunnz is offline
Real Name: I don't have real time
Just a computer user...
 
Join Date: May 2008
Location: See Google Maps
Posts: 101
Default

Wow that's very nice it should be a very trivial change to make it return with IP instead, thanks a lot!!
__________________
She sells C shells by the seashore.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amazon's second hand sales section reliable? Hashirsahebbb Off-Topic 3 28th March 2009 09:04 PM
best package management method TerryP Off-Topic 9 18th June 2008 03:57 PM


All times are GMT. The time now is 07:58 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick