Writing Server Addresses of Incoming Connections To File - linux

So I am currently working on a destination based routing setup, and I'm really new to the world of Linux. I'm mainly trying to get this to work for video, so what I want to do is route any traffic that I specify through my vpn, and keep the rest of the traffic local. I tried to do this with BBC iPlayer, and I ended up reaching a roadblock because nslookup did not yield the server addresses for Akamai, BBC's CDN. I used tcptrack to find all the incoming connections onto my machine, and I sorted it by connection rate, and the top few would end up being the akamai servers. Well, once I figured this out, I am currently trying to automate the process, and I cannot get tcptrack to write to an output file. Does anyone know of a way to get tcptrack to write to a text file or know of a program that would be better suited to my purpose? What I currently do is use the route command and route the server address, both the one that tcptrack gets me and the nslookup address, through to my vpn using the syntax route add (server address) dev tun0. Any help would be appreciated!

Not sure if i understand the context correctly but if you want to direct specific traffic say based on client IP or domain name then this is possible using Akamai.

Related

Throttling/Restricting localtunnel-server traffic

We've developed a server software and for ease of use for end-users, we are using the localtunnel-server app on one of our linux servers to get around the need for port forwarding and messing around with firewalls.
The problem is that it seems to tunnel "all" traffic on the port 80. However, we are afraid of this being abused. We would like to restrict traffic somehow and I wanted to know if that was even possible.
For example, let's say our app uses the "/myapp" virtual directory on the localhost website. So if a request is supposed to go to http://localhost/myapp/index.html then the traffic gets tunneled to http://mytunnel.myserver.com/myapp/index.html
The problem is, if there are other sites running on localhost, http://localhost/someotherapp also gets through. We'd like to block urls that don't match a format or contain keywords such as "/myapp"
Is that even possible? And if so, any guidance on how to achieve this, would be greatly appreciated.

Find external IP address of node js server in all scenarios

I have build a node js code for an API server. Part of one feature is that when it starts, it should be able to know its own IP, despite the type of setup of the server where it is running.
The classic scenario is not that hard (I think). There are several options, like using the os module and find the ip or the external interface. I am sure there are other ways and some might be better, but this is the way I have been doing it so far. Feel free to add alternatives as informative as possible.
There is this case that I stumbled on. In one case, the web server was running on a google cloud instance. This instance has two IPs, one internal and one external. What I want is the external IP. However, when I use the method above, the actual external IP is not part of the object returned. The internal IP is declared as being considered as non-internal. Even when I run different commands from within the server command line, the only IP returned is the one that is actually internal and cannot be used to access the node server.
From what I understand, the instance itself is not aware of it's external IP. There might be a dns (I think) that redirects requests made to the external IP towards the correct instance.
While reading in the internet I read that problems getting the server's correct external IP might also rise when using load balancing or proxies.
The solution I thought about is to have the node js code make a request towards a service that I will build. This service will treat the node js servers as clients, and will return their external IPs. From experiments that I have done, the req object contains among others the information of the client's IP. So I should check first req.connection.remoteAddress and then the first element of req.headers['x-forwarded-for']. Ideally the server would make a request towards itself, but
I know there are external API like https://api.ipify.org?format=json that do just that - return the actual IP. But I would very much like to have the node js servers independent of services I cannot control.
However, I really am hoping that there are better solutions out there than making a request from the server which returns the server IP.
However, I really am hoping that there are better solutions out there
than making a request from the server which returns the server IP.
It is not really possible, you always rely on some kind of external observer / external request.
While reading in the internet I read that problems getting the
server's correct external IP might also rise when using load balancing
or proxies.
This is because not in all scenarios your own device is able to be self-aware of its external ip. There might be sitting behind some network, that means external address assigned to devices that forwards the WAN to it. (example : router) so when you try to obtain external ip from the devices interface itself, you end up obtaining an ip but inside the scope of the routers LAN and not the one used for external requests .
So if you really want to
Have a method to use in all scenarios
Not rely on 3rd party services
Only Solution :
Build your own ip echo service (you maintain and can use for future projects).

node js send html to network rather than only localhost server

I'm using node js trying to send my web-page to my network, I successfully call localhost:port in my computer using express as server, the webpage loads fine trigger my webcam which I used to streaming in the webpage, and then im working to make a simple app in my phone to directly access my server, so my questions:
1.How do I able to access my server from different devices in the same wireless-network? by calling ip + port ?192.168.1.104:9001 ? cause i've tried and it didnt work.
2.I've found https with .pem something like that, is that the answer ? is there also any other way ?
3.maybe any advice before i work to make my web-app to devices? using koa? i don't even really know what is that, but i'm happily take any advices.
EDIT: i've read How could others, on a local network, access my NodeJS app while it's running on my machine?
let's say I simply using random router, so i can't configure my router-port, my server in my pc and my phone join in the same network, trying to access the server in my phone
1.How do I able to access my server from different devices in the same wireless-network?
All you need to do is find your server's IP address in this same wireless-network, and find the Node.js application's port. Then access the following URL in other devices:
http://{server_IP}:{port}
However, there are some points need to check:
Need to check firewall and confirm the port is not blocked, server IP is not blocked by test device, and test device IP is not blocked by server.
Need to check whether there is any Proxy setting in server and test device. If there is any, disable the proxy.
A computer may have many IP addresses at the same time, you need to find the correct one in the same wireless-network. For example, If you install a virtual machine software such as VMware and run a virtual system inside, your real computer will get IP address as 192.168.*.* -- this IP address looks like an intranet IP in wireless-network, but it is not, and can never be accessed by test device.
2.I've found https with .pem something like that, is that the answer?
No, HTTPS has nothing to do with this problem. HTTPS just add security (based on HTTP layer), it does not impact any HTTP connectivity. Actually, to minify the problem, it is better to only use HTTP in your scenario.
There is only one very special case that may bring your problem by HTTPS -- the test machine is configured and will block any non-HTTPS connection for security.
3.maybe any advice before i work to make my web-app to devices? using koa?
My suggestion is: As there is an HTTP connectivity issue, the first step is trying to find the root cause of that issue. Thus, it is better to make a simplest HTTP server using native Node.js, no Koa, no Express. In this way, the complexity of server will be reduced, which makes root cause investigation easier.
After the HTTP connectivity issue is fixed, you can pick up Koa or Express or any other mature Node.js web framework to help the web-app work.
4.let's say I simply using random router, so i can't...
Do you mean your server get dynamic IP address by DHCP? As long as the IP is not blocked by test device, it does not matter.

How do I convert a lot of IP addresses to URLs in Python? Is this possible?

I have a .csv file with a bunch of IP addresses. I am looking for a way to run a script to import the file and convert them to URLs and maybe export them to another .csv or something similar. Is this possible? How would I do this? Admittedly, I am a novice when it comes to python. I have done enough research to know that a call to sockets is involved, but that's where the trail ends. I don't know where to go from there. Any and all help is greatly appreciated. Thank you in advance.
You cannot convert them to specific URL's, but I guess you want to get the domain names. This is called Reverse DNS Lookup.
You can run this command nslookup <IP-ADDRESS> and get the domain name (besides other info).
Example:
nslookup 75.126.153.206
However, this does not guarantee that only that domain is associated with that IP. This is due to load balancers, and you will get the load balancer's domain name as a result most of the times. To avoid that you can try to do a Reverse IP Lookup. This will provide you all the domains associated with that IP address (online example https://hackertarget.com/reverse-ip-lookup).
Besides that, detecting the protocol (http/s, ftp) is another story. You have to scan the targets for specific ports like 80 (http), 443 (https), 21 (ftp) etc. to verify for they services they run. Again this does not guarantee that a service is definitively running on default ports (like web servers a lot of time may run on 8080 or some other port). To avoid that you may need to scan for a wider range of ports and detect their services which will be far more time consuming and you may get into trouble by getting your IP banned since somewhere this may be considered illegal.
Anyway for port scanning I suggest you to take a look at Nmap (https://nmap.org/)
import requests
def ip_to_url(ip):
try:
r = requests.get(f'http://{ip}', timeout=1).url
return r
except:
return 'not found'
print(ip_to_url('142.250.189.238'))
Output
http://www.google.com/

Rerouting When Using Own Computer As Server

I am currently making a website. I'd want people to try it out. They can do so right now if I send them my IP and port and they put it in the URL. My computer acts as the server right now.
Is there a way to use my computer as the server but without actually sharing directly my IP? Some kind of rerouting. I am not looking for something very secure, I am only looking for a solution that doesn't involve putting my IP in the URL.
You can register a domain name (or use a free equivalent like FreeDNS), but your IP will still be visible to anyone who pings you server. You could rent a VPS and use that to proxy requests to your server, or you could use an anonymizing service like Tor to keep your IP hidden, but there's really no reason to go through all that trouble. If you're worried about people having your IP address, there's no reason to, because there's not really much people can do with it. If you're looking for an easier way for you to share it and for people to remember it, I suggest FreeDNS or No-IP.
You might want to look into using ngrok - https://ngrok.com/.
It allows you to run general internet traffic to any port on your local machine, via somesubdomain.nkgrok.com. Also, it works if you're behind a firewall - you just open up a connection to ngrok from your computer, and ngrok will forward incoming traffic to your computer through that connection.

Resources