[SOLVED] How do I get IP Address from MAC Address?
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Now I would like this ip address written to /etc/cups/printers.conf
Here is what mines look like,
Code:
# Printer configuration file for CUPS v2.2.11
# Written by cupsd on 2019-03-27 08:49
# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING
<Printer MX490>
UUID urn:uuid:ba2476f1-8860-3a4d-5736-05fb35020ed7
Info Canon MX490 series
Location Wireless Printer
MakeModel Canon MX490 series - CUPS+Gutenprint v5.3.1
DeviceURI ipp://192.168.0.21:631/
State Idle
StateTime 1553694514
ConfigTime 1553694514
Type 36876
Accepting Yes
Shared No
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
Option job-cancel-after 10800
Option media na_letter_8.5x11in
Option media-col media-bottom-margin
Option output-bin face-down
Option print-color-mode color
Option print-quality 4
Option printer-resolution 601x600dpi
</Printer>
So every time I shut the computer down/restart it has the correct printer ip and I don't have to use avahi. Setting static ip doesn't work for me so I needed a different approach.
PROBLEMCHYLD - You said thru a router? Do you mean thru the switch on the back of the router? You will not be able to discover the MAC address having only the IP address unless your machine is on the same subnet and physical segment; those conditions are most likely true if you are both connected by switch; or even if you are connected via wifi and the 'router' bridges to the local ethernet segment.
If however the router is actually routing in this scheme; you can't do this. You will need to query the router in some way to obtain this information.
Yes..... chris.willing script does what I need atm. It gives me the ip addr of my printer using the MAC address. Now all I need is that ip address written to printers.conf on every shutdown and restart. Thanks guys....
Distribution: VM Host: Slackware-current, VM Guests: Artix, Venom, antiX, Gentoo, FreeBSD, OpenBSD, OpenIndiana
Posts: 1,008
Rep:
Quote:
Originally Posted by PROBLEMCHYLD
Yes..... chris.willing script does what I need atm. It gives me the ip addr of my printer using the MAC address. Now all I need is that ip address written to printers.conf on every shutdown and restart. Thanks guys....
depends on what you know about your network:
Quote:
netstat -r
to learn about broadcast address
ping broadcast:
Quote:
ping -b -c 3 xxx.xxx.xxx.255
you will get timeout
finally run:
Quote:
arp -a
now it will list all connected devices ip addresses/MAC adresses on your network
Yes..... chris.willing script does what I need atm. It gives me the ip addr of my printer using the MAC address. Now all I need is that ip address written to printers.conf on every shutdown and restart. Thanks guys....
None of this should be necessary. If the printer is getting a dynamically assigned address, then you should configure the router to reserve an address specifically for the printer (identified via its MAC address). Usually I would recommend using a static IP address for such devices.
None of this should be necessary. If the printer is getting a dynamically assigned address, then you should configure the router to reserve an address specifically for the printer (identified via its MAC address). Usually I would recommend using a static IP address for such devices.
I have done this but it seems DHCP Reservations get stale and after a reboot ip addresses have changed. Its a headache to do something manually, just to have it screwed up later. This might be a possible solution for me. Thanks for all the input.
I think you could do it with a sed command. You'd need to store the IP in a variable like $IP, then you should be able to use a sed command like below to adjust it in that conf file.
Code:
sed -i 's|DeviceURI.*|DeviceURI ipp://$IP:631/|' /etc/cups/printers.conf
(NOTE: I would run this without the -i option to see if it properly changes the file. It will just output the changes to the console rather than editing the file directly. I'm just not at home to check it myself.)
But, it seems like all this work could be easily solved with DHCP Reservation or DHCP Static Lease (or similar wording) that is available on most routers. What this allows you to do is put in a MAC address in your router and tell it to always assign a specific IP to that device. This still allows devices to be set to DHCP, but will essentially guarantee that the IP address won't change. I do it for many devices on my network so I don't have to manually set static IPs for those devices (and I'll always know what IPs those devices will be).
Check over your router settings or documentation to see if your router supports it (I'd be surprised if it doesn't -- even most ISP provided modem/router combos I've seen support this).
That was already suggested, however the OP mentioned something vague about stale leases (which doesn't make sense to me).
I've never seen a router that has issues with this, so there is a possibility that it's misconfigured or it's one of the (possibly?) few routers that does actually screw this up. If that's the case, I'd highly recommend making sure the router firmware is up-to-date and even checking if 3rd-party firmware is available like dd-wrt, open-wrt, tomato, etc.
I've been using static leases for probably close to a decade, but I've always had routers that can use dd-wrt.
@PROBLEMCHYLD, if you do want to try static leases/dhcp reservation, make sure you have the lease time set to 0 minutes. That should make the static leases permanent.
It is possible your router won't keep those IPs from getting reserved by other devices if those other devices are first on the network. Have you tried to use DHCP reservations outside of your addresses that the DHCP server will give out? For example, my router will give out addresses from x.x.x.50 to x.x.x.100. My static reservations are all x.x.x.101 and higher. Those addresses can't be automatically given out.
Either way, I do think my above sed command will work to replace that line in your printers.conf file, but I just haven't checked it.
Minor correction with my sed command. I always forget that the shell won't expand variables if they're included within single quotes. You just need to change the single quotes to double quotes to fix that. (I finally ran it on my computer and found my blunder.)
Code:
sed -i "s|DeviceURI.*|DeviceURI ipp://$IP:631/|" /etc/cups/printers.conf
@PROBLEMCHYLD
I'd try what bassmadrigal suggested in post #26, recalling now that I experienced myself such issues with some weird Chinese (HUAWEI/ZTE) routers, not respecting the static leases I defined based on MAC-Address when these were inside the DHCP pool.
In you particular case, make sure first that in your LAN configuration you define (route) the whole 192.168.0.0/24 subnet - netmask 255.255.255.0 - broadcast 192.168.0.255, and then look at the size of the DHCP pool, maybe shrink it to 192.168.0.10-150 and configure a static lease for your printer at 192.168.0.151
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.