I am working on a project using mongodb, express and nodejs to build an intranet based webapp. The goal of the project is to acquire a user mac address upon authentication and run a remote ssh. I am however finding it difficult to get the remote pc mac address. The clients and server are meant to be on the same local subnet. I tried using the node getmac module, but apparently it only gives host server's mac,
var macAddress = require('getmac');
require('getmac').getMac(function(err, macAddress){
if (err) throw err
console.log(macAddress)
});
I also tried the macfromip module but with that you have to predefine the host IP to get the mac of the remote computer.
var macfromip = require('macfromip');
macfromip.getMac('192.168.1.100', function(err, data){
if(err){
console.log(err);
}
console.log(data);
});
Is there any other way i could get the user's mac address?
Doesn't seem like you can get the MAC address from a IP.
The documentation of getMac doesn't have anything related to .getMac('192.168.1.100')
A way I would see this working is having a database with the IPs and their MAC address.
This would require something to save those each MAC address in the database. Probably a script running on startup on each computer.
Someone asked this question on security.stackexchange.com. As it is on the same network, if you use the command ping on the command line, the MAC address of that IP would be registered on ARP list.
ping your_ip_address
And with this you should be able to get the MAC Addresses:
arp -a
With that in mind, I found these 2 nodejs packages that might interest you:
https://www.npmjs.com/package/ping and https://www.npmjs.com/package/node-arp
I imagine you would have to do this client side and pass it back.
By the sounds of this SO answer you can't do it easily in in Javascript but the answer suggests:
Using Java (with a signed applet)
Using signed Javascript, which in FF (and Mozilla in general) gets higher privileges than normal JS (but it is fairly complicated to set up)
Related
I am using Nodejs with the express, bcrypt and body-parser packages on an ubuntu linux system.
Everything works fine so far.
However, I´ve been wondering if there is an easier way to connect to my website.
Until now, I have to type in my IP adress, e.g. https://XXX.XXX.XXX:3000 to actually see the content.
I´ve already tried avahi-daemon but did not get it work. Whenver I try 'hostname.local' I get the same error: Firefox is unable to connect to server.
However, using the IP-Adress: https://XXX.XXX.XXX:3000 works.
I would like to access my NodeJS sever with something similar to: computername.local
FYI: I just want to use it in my local network at home.
Does anybody have any idea how to get this work?
You have a couple choices. The easiest,if available, is probably to setup your home router to always assign it the same IP address (how to do that will vary based on your router). If your router has it available, you could also set a host name for it there in DNS settings.
If your router doesn't have DNS settings available, then you can add a line to each of your home computers /etc/hosts file (if memory serves Windows has it in C:\etc\hosts). Let's say the IP you give the server is 172.16.1.11, your hosts entry would be
172.16.1.11 computername.local
You could also setup your own DNS server in your house, possibly even on the same machine as has your node app, and then configure it to handle the one address before forwarding DNS requests for others to your ISP but that seems like overkill if you have just one app.
In a local network (over which I supposedly have no control) I need to connect my local instance of a meteor app to a MongoDB that is running on another PC. Using something like MONGO_URL="mongodb://192.168.1.xx:27017" meteor I am able to connect to it; However is there some way to connect when I don't know the IP, given that it may change daily?
What I'm attempting here would be something like:
Meteor.startup(() => {
//Script to find the correct IP
//Connect my app to that MongoDB instance
});
In short: is there some way to set the MONGO_URL dynamically?
Thank you
Use the hostname of the MongoDB server. As long as you have a local DNS server and both computers are using the same DNS server (which is most likely the case unless you have customised the network settings on either PC), the name will be resolved to the IP address.
To get the hostname of the server, type hostname into Command Prompt (or Terminal if on a Mac).
Alternatively, even without control over the network you may be able to configure a static IP address on the MongoDB server as long as you have local administrator permissions. Just make sure it is within the same network range as the rest of the network, but try to steer clear of your DHCP range otherwise you may get IP conflicts.
I have a website built on top of expressjs and node.js which is running fine on my localhost. How can i make it to run on my ip(192.168.69.100) instead of localhost so that other users on my LAN can access it.?
Thanks in advance. :)
A snippet of my code
app.listen(port,function (err) {
if(err)
{
console.log(err);
}
console.log('Running on ' + port);
});
By default node will run on every IP address exposed by the host on which it runs. You don't need to do anything special. You already knew the server runs on a particular port. You can prove this, by using that IP address on a browser on that machine:
http://192.168.69.100:port
If that didn't work, you might have your IP address wrong.
Might be good to give the device running node a fixed-ip if you're using DHCP; at some point your IP-address might change and the server is not accessible anymore. Alternatively you can use your hostname after some additional work.
I've used npm http-server a few times to broadcast my mac's filesystem over the LAN so I can access it via the different OS devices and their browsers in my home, instead of enabling file sharing in system preferences. I used the basic code, and connected successfully via localhost, and my ip address + port on other devices:
http-server [path to broadcast/serve] -p [random port] -o
I know this is not a good idea as anyone who can connect and guess the port can access my system, so I'm wondering if there is a way to password protect this connection. Can users be given an authentication prompt when trying to connect to [myip]:[port]? I tried fooling around with http-server's -S -K and -C options, but couldn't figure out how to create these .pem files properly, or connect them to the server command.
I've also tried http-auth, and was able to create a prompt with the following code:
var http = require("http");
var auth = require("http-auth");
var basic = auth.basic({
file: __dirname + '/htpasswd'
});
http.createServer(basic, function(req, res) {
res.end('User successfully authenticated: ' + req.user);
}).listen(8080);
It works, but the response stays static with 'user successfully authenticated: [user]', and doesn't continue to access my server (my filesystem).
I know I'm new to this, but have been attempting to password protect this type of local network connection for about a week. Any ideas?
First, the basic. It's true that with the default command everyone can browse your filesystem if s/he guesses the port, but if you're behind a firewall and/or NAT, only those inside your local network can connect to your computer. If you're the only person that connects to your LAN, then it's "safe" (assuming your Wi-Fi network can be trusted).
Second, if you're using that server just inside your LAN, you most probably won't need SSL (for which the -S, -K and -C options are). SSL is just about adding cryptography to the connection but it does NOT provide authentication.
SSL is very important over the public Internet, where the network can't be completely trusted (somebody could be listening - "sniffing" - your traffic). However, inside a LAN you're either connected via a cable or a Wi-Fi with encryption enabled, like if you're using WPA2 (if you're not using WPA2, enable it right now, not just because of this server!). Your connection will already be protected against eavesdroppers on a secure network, so you should be fine.
Third, that code you posted will indeed require authentication (using HTTP Basic Auth, which is fine for your use case), but it does not contain any code that lists the filesystem and allows exploring it.
To my knowledge, there's no pre-made utility similar to http-server that supports authentication out-of-the-box. You could hack your way around it, but it may just be much easier to use OSX's built-in file sharing tools (which are also safer and support different kinds of authentication). You can always use a simple app on your other devices - and you get full access to the file system, also in read/write!
I'm having difficulties understanding why the following line of code works in node.js:
server.listen(12345, "127.0.0.1"); // works
but this one does not:
server.listen(12345, "localhost"); // fails
Coding localhost literally results in the following error thrown:
events.js:45
throw arguments[1]; // Unhandled 'error' event
^
Error: ECONNREFUSED, Could not contact DNS servers
at IOWatcher.callback (dns.js:74:15)
I do not understand why it should 'contact DNS servers' as it's localhost as defined in my HOSTS file (I'm using node.js under Windows).
Why doesn't hardcoding localhost work?
Are uou using cygwin build? Did you try 'Set up Domain Name Resolution (DNS)' :
Cygwin internally uses Windows for DNS queries. node.js uses the c-ares library that relies on /etc/resolv.conf. Cygwin ships with an empty /etc/resolv.conf. In order to enabled networking from your scripts, add these IPs to the file (Google Public DNS):
$ vim /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
It turned out that using the cygwin build was the problem.
I looked at http://nodejs.org/ and I discovered that only recently a native Windows binary file was made available, which works like a charm.
I've never personally used node.js, however some quick searching turned up some interesting results...
From what I can tell, everything I've seen says that you need to find the IP address that you are looking to listen to. Here is an example: Get local IP address in node.js this behavior makes sense too. Domain names are arbitrary, it's the IP that matters so sometimes that is all something wants to deal with.
If I'm missing something about how node.js works I am sorry.