ip-address

C++ Windows function call that get local hostname and IP address

泄露秘密 提交于 2019-12-18 03:36:07
问题 Is there built-in windows C++ function call that can get hostname and IP address? Thanks. 回答1: To get the hostname you can use: gethostname or the async method WSAAsyncGetHostByName To get the address info, you can use: getaddrinfo or the unicode version GetAddrInfoW You can get more information about the computer name like the domain by using the Win32 API: GetComputerNameEx. 回答2: Here is a multiplatform solution... Windows, Linux and MacOSX. You can obtain ip address, port, sockaddr_in,

Finding a public facing IP address in Python?

ⅰ亾dé卋堺 提交于 2019-12-18 02:05:07
问题 How can I find the public facing IP for my net work in Python? 回答1: This will fetch your remote IP address import urllib ip = urllib.urlopen('http://automation.whatismyip.com/n09230945.asp').read() If you don't want to rely on someone else, then just upload something like this PHP script: <?php echo $_SERVER['REMOTE_ADDR']; ?> and change the URL in the Python or if you prefer ASP: <% Dim UserIPAddress UserIPAddress = Request.ServerVariables("REMOTE_ADDR") %> Note: I don't know ASP, but I

Can I get ip address inside my docker container?

女生的网名这么多〃 提交于 2019-12-17 22:44:37
问题 How to get container ip address inside this container? 'docker inspect $hostname ...' not suitable, because I don't share /var/run/docker.sock host file to container. 回答1: As the IP address is in the first line of /etc/hosts, you can do in a container the awk command that prints the first word of the first line of /etc/hosts gg@805689be5f47:/$ awk 'END{print $1}' /etc/hosts 172.17.0.14 回答2: I can find the IP address with hostname -i Of course, that may not be completely accurate if there is

Rails 3: Validate IP String

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 22:38:45
问题 In Rails 3, is there a built in method for seeing if a string is a valid IP address? If not, what is the easiest way to validate? 回答1: Just wanted to add that instead of writing your own pattern you can use the build in one Resolv::IPv4::Regex require 'resolv' validates :gateway, :presence => true, :uniqueness => true, :format => { :with => Resolv::IPv4::Regex } 回答2: The Rails way to validate with ActiveRecord in Rails 3 is: @ip_regex = /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.(

Find the IP address of the client in an SSH session

被刻印的时光 ゝ 提交于 2019-12-17 21:26:26
问题 I have a script that is to be run by a person that logs in to the server with SSH. Is there a way to find out automatically what IP address the user is connecting from? Of course, I could ask the user (it is a tool for programmers, so no problem with that), but it would be cooler if I just found out. 回答1: Check if there is an environment variable called: $SSH_CLIENT OR $SSH_CONNECTION (or any other environment variables) which gets set when the user logs in. Then process it using the user

How can a server find real client IP address?

假如想象 提交于 2019-12-17 21:22:48
问题 I can only access the internet from my place from behind a NAT and a proxy. This site however also shows my machine's private LAN address, as well as my NAT's public address. They are apparently using javascript in the process, but I can only find code where they set the value, but not how they find it. So, how can we find out the private IP address of a client machine using javascript? 回答1: Are you sure you're behind just a NAT router? If you're behind a proxy, the proxy might well be adding

Python - Get localhost IP [duplicate]

随声附和 提交于 2019-12-17 18:55:39
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Finding local IP addresses using Python's stdlib To get my localhost IP address I do socket.gethostbyname(socket.gethostname()) . But it gives me the answer 127.0.0.1 . If I do an_existing_socket.getsockname()[0] I get the answer 0.0.0.0 . I need my 'real' ip address (for instance 192.168.x.x) to modify a configuration file. How could I get it? 回答1: I generally use this code: import os import socket if os.name !

Getting IPV4 address from a sockaddr structure

江枫思渺然 提交于 2019-12-17 17:37:05
问题 How can I extract an IP address into a string? I can't find a reference that tells me how char sa_data[14] is encoded. 回答1: Once sockaddr cast to sockaddr_in , it becomes this: struct sockaddr_in { u_short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; }; 回答2: Just cast the entire sockaddr structure to a sockaddr_in. Then you can use: char *ip = inet_ntoa(their_addr.sin_addr) To retrieve the standard ip representation. 回答3: inet_ntoa() works for IPv4; inet_ntop()

Get Local IP-Address using Boost.Asio

╄→гoц情女王★ 提交于 2019-12-17 15:36:17
问题 I'm currently searching for a portable way of getting the local IP-addresses. Because I'm using Boost anyway I thought it would be a good idea to use Boost.Asio for this task. There are several examples on the net which should do the trick. Examples: Official Boost.Asio Documentation Some Asian Page I tried both codes with just slight modifications. The Code on Boost.Doc was changed to not resolve "www.boost.org" but "localhost" or my hostname instead. For getting the hostname I used boost:

How to get city name based on IP address in java?

99封情书 提交于 2019-12-17 12:41:10
问题 Is it possible to know the city name based on IP address in java? 回答1: are you using jsp or what ? for city name over client side you can use google's API which will return you the geographical details of the user mapped with the IP. As google's documentation say you can get the following When populated, the google.loader.ClientLocation object is populated with the following metro-level granularity properties: * ClientLocation.latitude — supplies the low resolution latitude associated with