LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-27-2019, 09:10 AM   #16
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled

Thanks chris.willing, but now here comes the hard part.

After running the script I get

[root@darkstaresktop] # ./printer.sh 00:bg:c1:39:79:ce
192.168.0.21

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.
 
Old 03-27-2019, 09:12 AM   #17
chemfire
Member
 
Registered: Sep 2012
Posts: 422

Rep: Reputation: Disabled
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.
 
Old 03-27-2019, 09:21 AM   #18
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by chemfire View Post
PROBLEMCHYLD - You said thru a router?
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....
 
Old 03-27-2019, 10:53 AM   #19
Aeterna
Senior Member
 
Registered: Aug 2017
Location: Terra Mater
Distribution: VM Host: Slackware-current, VM Guests: Artix, Venom, antiX, Gentoo, FreeBSD, OpenBSD, OpenIndiana
Posts: 1,008

Rep: Reputation: Disabled
Quote:
Originally Posted by PROBLEMCHYLD View Post
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

Last edited by Aeterna; 03-27-2019 at 10:56 AM.
 
Old 03-27-2019, 02:57 PM   #20
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,804

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
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.
 
Old 03-27-2019, 03:24 PM   #21
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ferrari View Post
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.
 
Old 03-27-2019, 08:28 PM   #22
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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).
 
Old 03-28-2019, 02:21 AM   #23
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,804

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
That was already suggested, however the OP mentioned something vague about stale leases (which doesn't make sense to me).
 
Old 03-28-2019, 03:24 AM   #24
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by ferrari View Post
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.
 
Old 03-28-2019, 10:05 AM   #25
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled
Here is an example of my DHCP Reservations not sticking and it very annoying.

Screenshot 1 has been set with specific ip addresses

Screenshot 2 shows the devices connected but with the wrong ip addresses

PrinterW in screenshot 1 has the wrong ip, just look at screenshot 2 with the android names.

Last edited by PROBLEMCHYLD; 09-27-2019 at 09:52 PM.
 
Old 03-28-2019, 10:13 AM   #26
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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.
 
Old 03-28-2019, 10:16 AM   #27
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bassmadrigal View Post
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.
IDK, but I'll try something new over the weekend. I'll try your command as well and report back. Thanks
 
Old 03-29-2019, 01:42 AM   #28
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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
 
Old 03-29-2019, 01:08 PM   #29
abga
Senior Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 1,634

Rep: Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929Reputation: 929
@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
 
Old 03-29-2019, 02:11 PM   #30
PROBLEMCHYLD
Senior Member
 
Registered: Apr 2015
Posts: 1,201

Original Poster
Rep: Reputation: Disabled
Your command needs to be added to the script below after output of the correct ip address. Something I don't know how to do on Linux.
Quote:
Originally Posted by bassmadrigal View Post
Code:
sed -i "s|DeviceURI.*|DeviceURI ipp://$IP:631/|" /etc/cups/printers.conf
Code:
#!/bin/sh

TMPFILE=`mktemp` || exit 1

sudo nmap -sP 192.168.20.0/24 -oN $TMPFILE 2>/dev/null 1>/dev/null
if [ -z $1 ]; then
  TARGET=MAC
  cat $TMPFILE |head -n -1 |tail -n +2 |paste -d " " - - - |grep -i $TARGET
else
  TARGET=$1
  cat $TMPFILE |head -n -1 |tail -n +2 |paste -d " " - - - |grep -i $TARGET | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]* "
fi

rm $TMPFILE
If it comes down to just doing it manually, I'll just have to deal with it. Thanks again everyone...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change mac address to multicast mac address ubuntuv Linux - Networking 5 01-16-2019 07:21 AM
how do I find what MAC address web pages see as my MAC address rob.rice General 20 05-29-2010 02:08 AM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 04:33 AM
Is there a way to get an IP address from a MAC address? Thaidog Linux - Networking 4 03-01-2004 08:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration