ip-address

Rails 3 validate IPv4 and IPv6 format

倖福魔咒の 提交于 2019-12-07 03:26:47
问题 I know the validation format for IPv4 and IPv6. But not sure how I can combine them so atleast one format should be true. Here is my validation validates :src_ip_addr, :presence => true, :uniqueness => true, :format => { :with => Resolv::IPv4::Regex, :message => "Not an valid IPv4 format"} validates :src_ip_addr, :presence => true, :uniqueness => true, :format => { :with => Resolv::IPv6::Regex, :message => "Not an valid IPv6 format"} How I can combine them so if one format is correct then

Dynamically changing the source IP address

牧云@^-^@ 提交于 2019-12-07 00:59:25
I have a server with a couple of different IP addresses. At this point, each IP can recieve a UDP request, but it is always the same IP that replies, which the requesters do not like. To make a long story short, this is all the essential code: int sock; socklen_t clilen; struct sockaddr_in serv_addr, cli_addr; memset((char*)&serv_addr, 0, sizeof(serv_addr)); sock = socket(AF_INET, SOCK_DGRAM, 0); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(PORT); ... recvfrom(sock, buffer, BUFLEN, 0, (struct sockaddr *)&cli_addr, &clilen); ...

How to split an ip address into seperate octets and perform arithmetic in cmd

五迷三道 提交于 2019-12-06 21:02:36
What I am trying to do is configure some vlan scopes via cmd. What I have accomplished so far is to retrieve the IP Address of the Domain Controller and remove the space in front of the value. I have accomplished this using the following commands: rem extract ip address via local cmd for /f "tokens=2 delims=:" %i in ('ipconfig ^| find /i "IPv4 Address"') do set ip_address=%i example result: set ip_address= 10.0.0.25 rem remove empty space from ip address var set ip_address=%ip_address: =% echo %ip_address% now results in 10.0.0.25 without the space in front. What I would like to do next is

How do I find a computer's IP address?

喜欢而已 提交于 2019-12-06 16:36:51
I am writing a program in C++ which uses network sockets. I need to find out what the computer's IP address is, so I can display it to the user. The program must run on Windows and Linux. I have heard somewhere that a computer can have multiple IP addresses. I want the one that other programs on different computers can use to connect to the computer. Here is the relevant code I already have (the variables are declared in other places): master = new fd_set; FD_ZERO(master); struct sockaddr_in my_addr; listener = socket(PF_INET, SOCK_STREAM, 0); my_addr.sin_family = AF_INET; my_addr.sin_port =

getting ip address using PHP in case you are running VPN

我与影子孤独终老i 提交于 2019-12-06 16:16:56
问题 I am using VPN, and thus if i check http://whatismyip.com it will give me different ip than $_SERVER['REMOTE_ADDR'] or getenv('REMOTE_ADDR') . whatismyip gives my original ip address while $_SERVER or getenv gives my VPN ip address !! is there anyway to get my original address ip using php in case that i am running VPN? and is there any way to get the PROXY IP address using PHP if i am using proxy also? Thanks 回答1: No. Whatever PHP (rather the web server) returns is the address that the

adding counter to php page to count the unique visitors

淺唱寂寞╮ 提交于 2019-12-06 15:59:32
问题 I want to add a counter in my webpage which counts the number of visitors. But my problem is that when i refresh my page ,counter increases by 1..i want that counter increases only when a new visitor with another ip reaches to my webpage. here are my codes.. Sorry for my weak english index.php <?php session_start(); $ip = $_SERVER['REMOTE_ADDR']; $_SESSION['current_user'] = $ip; if(isset($_SESSION['current_user'])) { $count = file_get_contents("counter.txt"); $count = trim($count); $fl =

Finding the IP address in Adobe AIR

一笑奈何 提交于 2019-12-06 15:55:19
How to know the IP address of the system in which the AIR application is currently running, Or how to restrict the usage of AIR application for a particular country? jhloke Please try the following code, it works for me. import flash.net.InterfaceAddress; import flash.net.NetworkInterface; var netInterfaces:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces(); var addresses:Vector.<InterfaceAddress> = netInterfaces[0].addresses; ipAddress = addresses[0].address; 来源: https://stackoverflow.com/questions/1679215/finding-the-ip-address-in-adobe-air

Getting IP addresses of the PC's available on wifi network in android

旧城冷巷雨未停 提交于 2019-12-06 14:23:34
问题 I am able to establish connection between android and PC via Wi-fi. But this is done by hard coding the the IP address of the PC (server) in the android program. But I wanted to get IP addresses of the PC's available on the Wi-fi network programmatically. So please let me know how to scan for PC's on the network and get their respective IP address. 回答1: can you not multicast a UDP packet on the network which the server listens for and responds to with a packet containing the ip address of the

find internet ip address in android mobile programmatically , no need device ip address

蹲街弑〆低调 提交于 2019-12-06 14:16:15
i am trying to get the Internet Ip Address in my mobile. no need for device ip address. that device is connected with wifi or 3g or 2g or anyway. that mobile is having internet facility means, i need that internet IP Address. Note : already i tried some coding. that code will work to get the device ip address only. my prev code : try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();enumIpAddr.hasMoreElements();) { InetAddress

PHP user authentication using database and ip address?

纵然是瞬间 提交于 2019-12-06 13:23:48
问题 I have been considering the problems arising with user authentication, using sessions/cookies and the security risks that come up with session hijacking. I understand that using a secure https:// is the most effective method, as well as regenerate_session_id() and using a random string for validation (amongst numerous additional procedures). My question is this: is there a possibility to incorporate a method that forgoes sessions and cookies, and uses just database held variables? Here is how