ip-address

Validating IPv4 addresses with regexp

淺唱寂寞╮ 提交于 2019-12-16 20:30:02
问题 I've been trying to get an efficient regex for IPv4 validation, but without much luck. It seemed at one point I had had it with (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)){4} , but it produces some strange results: $ grep --version grep (GNU grep) 2.7 $ grep -E '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)){4}\b' <<< 192.168.1.1 192.168.1.1 $ grep -E '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)){4}\b' <<< 192.168.1.255 192.168.1.255 $ grep -E '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)

Validating IPv4 addresses with regexp

倖福魔咒の 提交于 2019-12-16 20:29:25
问题 I've been trying to get an efficient regex for IPv4 validation, but without much luck. It seemed at one point I had had it with (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)){4} , but it produces some strange results: $ grep --version grep (GNU grep) 2.7 $ grep -E '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)){4}\b' <<< 192.168.1.1 192.168.1.1 $ grep -E '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)){4}\b' <<< 192.168.1.255 192.168.1.255 $ grep -E '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(\.|$)

Get the IP address of the machine

别来无恙 提交于 2019-12-16 20:14:50
问题 This Question is almost the same as the previously asked Get the IP Address of local computer-Question. However I need to find the IP address(es) of a Linux Machine . So: How do I - programmatically in C++ - detect the IP addresses of the linux server my application is running on. The servers will have at least two IP addresses and I need a specific one (the one in a given network (the public one)). I'm sure there is a simple function to do that - but where? To make things a bit clearer: The

Getting the 'external' IP address in Java

大憨熊 提交于 2019-12-16 20:04:15
问题 I'm not too sure how to go about getting the external IP address of the machine as a computer outside of a network would see it. My following IPAddress class only gets the local IP address of the machine. public class IPAddress { private InetAddress thisIp; private String thisIpAddress; private void setIpAdd() { try { InetAddress thisIp = InetAddress.getLocalHost(); thisIpAddress = thisIp.getHostAddress().toString(); } catch (Exception e) { } } protected String getIpAddress() { setIpAdd();

Javascript calculate IPv6 range from CIDR prefix

你。 提交于 2019-12-14 03:59:09
问题 Using Javascript (without JQuery) I'm looking to get the minimum and maximum IPs in a IPv6 CIDR prefix. For example, 2001:280::/32 would output 2001:280:0:0:0:0:0:0 and 2001:280:ffff:ffff:ffff:ffff:ffff:ffff . How can I do this? Thanks in advance! 回答1: Assuming you have Node and NPM installed: $ touch index.js $ npm init $ npm i --save ip-address $ vim index.js var v6 = require('ip-address').v6; var addr = new v6.Address('2001:280::/32'); console.log(addr.parsedAddress.join(':')); console.log

How can I know the service name?

给你一囗甜甜゛ 提交于 2019-12-14 03:44:24
问题 This code from Stevens et al., Advanced Programming in the Unix Environment, Figure 16.17 is a server program to provide system uptime : #include "apue.h" #include <netdb.h> #include <errno.h> #include <syslog.h> #include <sys/socket.h> #define BUFLEN 128 #define QLEN 10 #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256 #endif extern int initserver(int, const struct sockaddr *, socklen_t, int); void serve(int socked); int main(int argc, char *argv[]) { struct addrinfo *ailist, *aip; struct

Simple Java regex to extract IP address and port from enclosing string

橙三吉。 提交于 2019-12-14 02:36:34
问题 Consider a pair of IPv4 or IPv6 address and port, separated by either / or : , e.g. 10.10.10.10:1234 The port is optional, so strings like 10.10.10.10/ 10.10.10.10: 10.10.10.10 are also valid. The address/port pair may be followed by space or comma characters and it is part of a much longer enclosing string. What would be a very simple regex to extract the 2 values in separate fields from the enclosing string (without using String manipulation functions)? For example, an expression like (?

Find out the active local IP

ぃ、小莉子 提交于 2019-12-13 21:07:29
问题 I need to find out the local Ip address, for that reason I was using the following code: IPHostEntry host; string localIP = ""; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { localIP = ip.ToString(); break; } } return localIP; I find out that when a PC has more than one IP with AddressFamily.InterNetwork I get always the first one. However I can't find any property to find out the active IP. How

How to incorporate the IP address of a device into a Python script if the address changes

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 20:34:15
问题 I have a Python script which retrieves the measured data from a smart plug so that I can visualize it on my Rasbperry Pi. This command gets the data send_hs_command("192.168.1.26", 9999, b'{"emeter":{"get_realtime":{}}}') and this is the define def send_hs_command(address, port, cmd): data = b"" tcp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: tcp_sock.connect((address, port)) tcp_sock.send(encrypt(cmd)) data = tcp_sock.recv(2048) except socket.error: print(time.asctime( time

Match partial IP with Elasticsearch

杀马特。学长 韩版系。学妹 提交于 2019-12-13 17:53:21
问题 In my index, I have an IP field. The type of the field is "ip". I want to search all IPs who starts with "192.168" All my tentative have failed with the following message: failed to parse ip [192.168], not a valid ip address Is there a way of doing this or should I change the type of the field to "string"? Thanks. 回答1: You can use range query for example like: GET my_index/_search { "query": { "range": { "ip_addr": { "gte": "192.168.0.0", "lt": "192.168.255.255" } } } } 来源: https:/