LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Automated way of loging into servers by netbios name instead of ip's (https://www.linuxquestions.org/questions/linux-networking-3/automated-way-of-loging-into-servers-by-netbios-name-instead-of-ips-833065/)

avalosdanielr 09-18-2010 12:49 PM

Automated way of loging into servers by netbios name instead of ip's
 
In recent days, (today is September 18, 2010) I've been surfing the web trying to learn how to access nodes in my soho lan by netbios names instead of having to connect through the ip number, because ip's change every time according to DHCP assignments.

I do not know what has happened to the "new" command mount.cifs, but things seem to have become a bit more complicated with the new version. Security problems, they say, and surely that's the reason.

I show here an automated way of loging into servers by netbios name instead of having to resort to the use of IP numbers, hosts files, wins servers and all that jazz. This is especially useful if your soho lan have five or more network nodes, and you do not want to go finding out the ip numbers assigned to the machines you want to connect to (temporarily or permanently).

This is my approach: instead of the usual mount.cifs command:

mount.cifs //ServerIP/Servershare/ /Localmountpoint -o user=yourID%yourPASS

I replaced it by the following:

mount.cifs //$(nmblookup ServerName | gawk '/<00>/ {print $ 1}')/Servershare /Localmountpoint -o user=yourID%yourPASS.

Thus, when executing "nmblookup ServerName" nmblookup returns as output:
(assuming the server ServerName has ip=192.168.1.122)

querying ServerName on 192.168.1.255
192.168.1.122 ServerName<00>

This output is piped to gawk to isolate the line containing <00>, and gawk outputs the first element (print $1) of that line, which happens to be the ip of the server ServerName.

I tested the script in my soho network, which now has Linux, Windows XP and Windows 7 nodes, and it worked perfectly for both tipes of servers.

I'm using GNU's gawk, but I'm pretty sure that awk would do the job just as well.

H_TeXMeX_H 10-18-2010 10:50 AM

Alright, thanks for solution.


All times are GMT -5. The time now is 02:54 AM.