ipv4/ipv6 network address match in node-js - regex

I am looking for something like python's netaddr.IPNetwork in node.js. Basically, i have IP network addresses like 1.1.1.1/30, 1::/128 and want to validate in the backend in express if the data provided by user is valid ip network?
Thanks,

found a good library: https://github.com/whitequark/ipaddr.js
var ipaddr = require('ipaddr.js');
var addr = ipaddr.parse("2001:db8:1234::1");
var range = ipaddr.parse("2001:db8::");
addr.match(range, 32); // => true

Related

Can't lookup ENS name on testnet of an address

I'm trying to create an app that works with ENS. I tried registering a test domain on Georli network. Here's the link when I lookup that test domain on app.ens.domains.
https://app.ens.domains/name/rikikudo6.test/details
I try using ethers to resolve ens domain as well as looking up a specific address. Here's the code I'm using:
var ethers = require("ethers");
// I use rpc endpoint generated by alchemy on Georli network
var provider = new ethers.providers.JsonRpcProvider(rpc);
(async () => {
var address = await provider.resolveName("rikikudo6.test");
console.log("address :>> ", address);
const ens = await provider.lookupAddress(address);
console.log("ens :>> ", ens);
})();
And here's the result when I run the above script:
address :>> 0x8A2D9D8e54FF47d28Cc35Aa2ba244d49F14944cA
ens :>> null
I don't understand why it can resolve the name for rikikudo6.test but can't lookup ens for the address returned by the resolving function. Am I missing anything?
I found the answer myself. The lookupAddress only returns the ENS name which is set to the default ENS name of user. If the user doesn't have the default ENS name, it will return null.

"requests-html" proxy setting not working

I'm using the following code to set the proxy for the HTMLSession, get() method. Still, it uses my IP instead of the proxy IP.
proxy string format:
http://username:password#ip:port
r = session.get('https://whatismyipaddress.com/', proxies={'http': proxy})
r.html.find('p.ip-address')[0].text
above print the following which is my current IP address.
'IPv4:? The most common IP version is assigned by ISPs. 175.157.?.?'
You need to add 'https' in proxies:
proxy = 'http://username:password#ip:port'
r = session.get('https://whatismyipaddress.com/', proxies={'http': proxy, 'https': proxy})

How can I find my personal endpoint in AWS IoT?

I'm trying to write a Java app that behaves as a Thing, publishing data in AWS. The Documentation has this code sample:
String clientEndpoint = "<prefix>.iot.<region>.amazonaws.com"; // replace <prefix> and <region> with your own
String clientId = "<unique client id>"; // replace with your own client ID. Use unique client IDs for concurrent connections.
String certificateFile = "<certificate file>"; // X.509 based certificate file
String privateKeyFile = "<private key file>"; // PKCS#1 or PKCS#8 PEM encoded private key file
// SampleUtil.java and its dependency PrivateKeyReader.java can be copied from the sample source code.
// Alternatively, you could load key store directly from a file - see the example included in this README.
KeyStorePasswordPair pair = SampleUtil.getKeyStorePasswordPair(certificateFile, privateKeyFile);
AWSIotMqttClient client = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);
// optional parameters can be set before connect()
client.connect();
I know what clientId is and how to find my ID, but I cannot understand the in clientEndpoint.
It's not the account's personal endpoint, but the Thing's endpoint.
Go to IoT Core -> Manage -> Things, select your thing -> Interact.
Its the URL under the HTTPS part. It should be in the form xxxxxxxxxxxxxxxxx.iot.region.amazonaws.com, where the x's should contain mainly lowercase letters, and maybe some numbers.
Call the DescribeEndpoint API.
In Java, this would be:
AWSIot awsIotClient = AWSIotClientBuilder.defaultClient();
DescribeEndpointRequest request = new DescribeEndpointRequest().withEndpointType("iot:Data");
DescribeEndpointResult result = awsIotClient.describeEndpoint(request);
String endpoint = result.getEndpointAddress();

WCF Self-Hosted ServiceHost Error with Multiple IP Addresses

I'm self-hosting a web service using WCF. The host computer has multiple ethernet ports, so I am creating the ServiceHost with multiple URIs. When I create the service host, I get the following error:
"This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item"
Following is the code:
Uri[] uriSet = new Uri[ipList.Count];
for (int i=0; i<ipList.Count; i++)
{
string baseAddress = string.Format("http://{0}:{1}/mynamespace", ipList[i], myport);
uriSet[i] = new Uri(baseAddress);
}
host = new ServiceHost(webServiceType, uriSet);
ipList contains the list of IP addresses for the host computer.
You can use the special IP address 0.0.0.0 or just localhost to match any IP address for the local machine. Therefore, you should only need one base address URI, with either localhost or 0.0.0.0.
host = new ServiceHost(webServiceType, new Uri[] { new Uri("http://localhost:80/mynamespace") });
or
host = new ServiceHost(webServiceType, new Uri[] { new Uri("http://0.0.0.0:80/mynamespace") });
* where 80 is the port.
https://msdn.microsoft.com/en-us/library/ms733768%28v=vs.110%29.aspx

GeoIP always shows the server's IP address

I am trying to use GeoIP, but I have a problem when I use REMOTE_ADDR. The IP shown is that of my server and not the client.
from django.contrib.gis.geoip import GeoIP
Example context:
g = GeoIP()
ip = self.request.META.get('REMOTE_ADDR')
context['my_ip'] = ip # this display ip client
context['pais_anuncio'] = g.country_code('ip') # this display ip my server.
What am I doing wrong, Thank you.
My guess is, since you are passing the string 'ip', it is defaulting to your server's IP. Try passing in the variable ip, like this:
context['pais_anuncio'] = g.country_code(ip)