Connect to Express server using it's IP address - javascript

Wanted to know if it's possible to connect to an express server using that servers UP address. If it is how would you do it?(some code examples would be very appreciated)

Same as with any http server. This is not specific to Express at all. It's just browsers and TCP.
From a browser, you would just type:
http://192.168.1.100/somePath
Where you put in the IP address of the server and the desired path for the URL.
If you're connecting programmatically, you'd have to tell us what client environment you're using so we could offer a relevant exampale. All TCP connections are fundamentally connecting via the IP address (that's how TCP connections work).
Some APIs allow you to use the DNS name and then the first step under the covers of the API is to look up the IP address that corresponds to that DNS name and then connect to the IP address.
Wanted to know if it's possible to connect to an express server using that servers IP address.
Yes, that's actually the only way to connect to any server that uses TCP as the transport. All TCP connections are made from one IP address to another IP address.

Just use the IP address in place of where you would put localhost or the domain.
For example:
https://www.google.com/ -> https://216.58.217.164/
https://localhost/hello.html -> https://127.0.0.1/hello.html
https://localhost:8080/ -> https://127.0.0.1:8080/
I can add a code sample if you add your current code to the question or say what you are using to make the connection.

Related

How to point my node.js app to a non existing domain

I have an app running on a server where I access using the servers ip. But now I need to have a subdomain configured in order to make an external API work but I have no clue of how achieve it.
Now I access to my server using IP -> XX.XXX.XXX.XXX:3000
And I need to change it for something like -> myapp.companyname.com
You don’t, because the Internet doesn’t work that way.
You create the subdomain by configuring the DNS server for the domain to point that subdomain at the IP address.
If you want to change the port number (from the default of 80 to 3000) without putting it in the URL itself, then you need to change the Node.js program or put a proxy server in front of it.
This is indeed a notorious problem with distributed web development. Presumably your API requires you to register your own hostname in some sort of allow-list, and then checks incoming requests for matches to that allow-list. (Why? Cybercreeps.)
You need to find out the IP address of your development machine (not 127.0.0.1, that's the loopback IP and every machine has it). It's OK if your development machine's address is on a private network, like '192.168.0.20for example. Give the commandifconfigand look for the address (it'sipconfig` on Windows).
You then need to put that IP address into a DNS server.
Here's a free way to do that.
Create a FreeDNS account by visiting https://freedns.afraid.org/
Click on Subdomains.
Click the Add link.
Create a subdomain hostname under one of FreeDNS's public domains. Maybe javier.ortega.mooo.com is a good choice
Put your machine's IP address into it.
Then, use https://javier.ortega.mooo.com:3000 to hit your development machine's nodejs app.
You can pay FreeDNS to register your own domain name and use that if you prefer.
The solution I needed was modifying the file hosts from -> system32/divers/etc/hosts and adding there the configuration relative to the ip - domain relation I was lookin for.

Citrix retrieve client IP address from web application

Situation
We have:
A JSF web application that runs on an Application Server.
A Java Server Socket application for smart card access that runs on the client computer.
The web application needs to read a smart card in a smart card reader on the client computer.
For this the web application makes a connection to the Server Socket application on the client computer with the IP address of the client computer.
This IP address is determined through ServletRequest object of our web application call.
Problem
When this setup runs in a RD environment (eg Citrix), we receive the server IP address instead of the client computer IP address.
Question
How can we retrieve the client IP address?
Perhaps by using WebSockets?
Comment
I am not sure if these are correct, but I have looked around and some possible solutions found are:
using a Virtual IP Policy (I understand that this would make the localhost call revert to the correct IP address?)
Adding a X-Forwarded-For header to the request
These would require modification/configuration of the RD environment and we don't manage this level.
Of course, if there is no other way, I can try to request this.
You should try X-Forwarded-For. Worked for us. Somehow different scenario but it worked for us.

Can i get clients DNS IP address using JS? [duplicate]

Detecting visitor IP is easy. But how about detecting DNS server ips of a visitor ?
I found this PHP function, however it finds only domain names' DNS.
dns_get_record("website.com", DNS_ANY);
Is it possible to detect visitor DNS server ?
Yes, you can, like detecting page resolution of visitors.
You need own DNS server and force user to resolve unique dns name. If user tried to resolve it then they will leaks to your DNS server own DNS server address. Next to DNS server have to share information who asked about the unique dns name to your web apps.
It's not easy, but it can be done. There's a demonstration of the approach suggested in a separate answer by Adam Dobrawy at http://ipleak.net/
To add a bit of detail, the way you can implement something like this is:
Part 1 - Set up your own DNS server on myspecialdomain.com
This DNS server needs to be custom written to log and store the incoming request and the source IP address. This storage only needs to be for a short period of time, so something like memcache might work nicely.
The DNS response should be an NXDOMAIN.
Part 2 - Your client-side code
In your Javscript make and store a large random number. Make the browser lookup .myspecialdomain.com. Load this via a JS img tag with an error handler.
In that error handler, now make a query to your server side code passing the random number.
Part 3 - Your web application (server side)
You need to implement some server side logic that takes the random string, looks it up in the datastore, and retrieves the IP address of the DNS server.
Note the IP address here will be the IP Unicast address of the particular server, it won't be an IP Anycast address like 8.8.8.8.
Here you can use GeoIP or Whois databases to determine the owner of that IP address (OpenDNS, Google etc). You can then generate a response to send to the client logic.
DNS resolution is not part of the request itself which means there is no way for the receiver of the request to know which DNS was used by the client (browser).
The DNS request happens first, as it is required to resolve the hostname to an IP address. Once this is complete, then a separate request is performed to the address in question.
The answer is NO. All the server got is a TCP connection to the visitor, that is, an [IP, Port] pair. DNS resolution depends on visitor's local configuration and can be done by a proxy.

Know local ip server from client in node.js

I have a Node.js server, the client is a mobile app. I want to know which would be the best way to know the local ip of the server. I mean...
Server runs in localhost:8080 and the client has to connect to the server like this 192.168.0.107:8080 (pc's local ip).
I want to guest this IP, 192.168.0.107 without writing it in client code because it could change.
My guess is that you have a server with a dynamic ip, you want to connect your client to this IP without hardcoding that to the client's code. I'd say have many options:
Set up DNS, so that you connect to a known hostname and then translate that into an IP with your DNS server.
Implement/use a discovery service using your network's broadcast address. (A server could regularly broadcast information to a broadcast IP, then your client will receive this information and use it to show the user a list of available servers)
Let the client have an input box where he can enter the IP address (this is the easiest way, just have a guy input the ip address, maybe save the address for future autocomplete etc)
IMHO this is not possible in a really reliable way. There are several reasons for this, including:
A server may have more than one IP, e.g. multiple network adapaters.
A server has an IPv4 and an IPv6 address.
…
So either you need to narrow down what you want to achieve or you have to live with some kind of uncertainness.
The easiest way then would be to do a DNS lookup, using the hostname, to get the well-known IP addresses, and then select one of them (however you want to do this, that's up to you).
PS: I'm not perfectly sure that I really got your question. If I understood you correctly, you want to find out the IP address of the client on the client, because you need to send it to the server, right?
If you are looking for a simple answer, there is a npm module that does this for you, it's really small so just install it and use the instructions to get the ip of the client:
https://www.npmjs.com/package/request-ip
Getting Started:
var requestIp = require('request-ip');
// inside middleware handler
var ipMiddleware = function(req, res, next) {
var clientIp = requestIp.getClientIp(req); // on localhost > 127.0.0.1
next();
};
Depending upon the network topology details of your actual implementation (which aren't included in your question), you have at least three different options:
Server Directly on Public Interent
On a public network (e.g the open internet), DNS is the normal answer to this type of question. You follow the following steps:
Make sure you have a public IP address. As you may or may not know 192.168.0.107 is not a public IP address. It is a local internet address and cannot be routed on the open, public internet.
With a DNS service, create a DNS record that establishes a link between a host name such as "google.com" and your public IP address.
Code the client to connect to your "name", not your IP address.
Server and Mobile App Only on Private Network
If your mobile app runs only on your private network (perhaps via WiFi), then you can configure your own DNS server on your private network that will do essentially the same thing as the steps above, but will work for a private address like 192.168.0.107 on your private network.
Server Lives on Home Network, Want to Access From Internet
If your server lives in your private network (and thus only has a private IP address), but you want to be able to reach it from the public network, then you need to configure some sort of routing or port forwarding at the boundary between your private network and your public network. In a home router situation, this would involve the following steps:
Get the public IP address of your home network connection.
Set up a public DNS entry on the open internet for that IP address.
If your public IP address is not a static IP address (e.g. it could change over time), then you may be able to use one of the "dynamic DNS" services that are built for this type of situation.
At your home router, configure port forwarding so that incoming requests from the internet on the port your web server is running on (usually port 80) or forwarded to the private IP address of your actual node.js server on your home network.
I got your question as this,
Your client have a private & dynamic IP because it is behind some NAT( i.e firewall),
mobile app can request some STUN server to get its public IP and Port, then mobile app can send these data to server to identify the client. Similar to peer-to-peer connection establishment.
Read more...

JSON restful service security

I am currently building a web application, that has fully separated a "frontend" server with Lighttpd only serving the index.html and javascript etc.
Backbone.js etc. keep my frontend in connection with my webservice "backend" written in Node.js
The backend is completely stateless, doing authentication each request through http basic and runs SSL (https).
How do I make sure that only the connections happening on my "backend" server are comming from the Lighttpd "frontend" server and not some random hacker?
Thanks for help.
If you know the front-end server is going to be on a specific IP address or range or IP addresses, you might want to restrict traffic on the back-end server to only be from that address.
You may use ssl between the 2 servers and use a certificate to ensure identification. That's really secure if you protect your certificate well.

Categories

Resources