ipify—A Simple IP Address API

一个简单的IP地址API。

你可以直接访问:[https://api.ipify.org/][1] 查看你的IP

你是否需要通过程序获取对外的IP地址?

也许你正在配置新的云服务器,需要知道你的IP。

也许你在公司的防火墙后面,需要tunnel信息。

不管是什么原因:有一个获取可以获取公共IP地址的API是没坏处的。

你值得使用 ipify是因为:

  • 你可以毫无限制地使用它(即使你每分钟做数百万个请求)。

  • 它总是在线并可用的,它的基础设施是由 Heroku 提供的,这意味着你不用管运行API的服务器是否挂掉了,如果有龙卷风摧毁了东海岸,ipify仍将运行。

  • 它兼容IPv4和IPv6地址,无论你使用什么样的技术,都不会有问题。

  • ipify是开源的,Git仓库

  • 从不记录访问者信息

  • 最后,ipify是 Randall Degges 资助的,所以不用担心它会消失

API的使用

示例

Bash

#!/bin/bash
 
ip=$(curl -s https://api.ipify.org)
echo "My public IP address is: $ip"

Python

# This example requires the requests library be installed.  You can learn more
# about the Requests library here: http://docs.python-requests.org/en/latest/
from requests import get
 
ip = get('https://api.ipify.org').text
print('My public IP address is: {}'.format(ip))

PHP


<?php
    $ip = file_get_contents('https://api.ipify.org');
    echo "My public IP address is: " . $ip;
?>

Java

try (java.util.Scanner s = new java.util.Scanner(new java.net.URL("https://api.ipify.org").openStream(), "UTF-8").useDelimiter("\\A")) {
    System.out.println("My current IP address is " + s.next());
} catch (java.io.IOException e) {
    e.printStackTrace();
}

NodeJS

var http = require('http');
 
http.get({'host': 'api.ipify.org', 'port': 80, 'path': '/'}, function(resp) {
  resp.on('data', function(ip) {
    console.log("My public IP address is: " + ip);
  });
});

JavaScript

<script type="application/javascript">
  function getIP(json) {
    document.write("My public IP address is: ", json.ip);
  }
</script>
 
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>

jQuery

<script type="application/javascript">
  $(function() {
    $.getJSON("https://api.ipify.org?format=jsonp&callback=?",
      function(json) {
        document.write("My public IP address is: ", json.ip);
      }
    );
  });
</script>

Go

package main
 
import (
        "io/ioutil"
        "net/http"
        "os"
)
 
func main() {
        res, _ := http.Get("https://api.ipify.org")
        ip, _ := ioutil.ReadAll(res.Body)
        os.Stdout.Write(ip)
}
展开阅读全文

A Simple Question of Chemistry

03-11

Your chemistry lab instructor is a very enthusiastic graduate student who clearly has forgotten what their undergraduate Chemistry 101 lab experience was like. Your instructor has come up with the brilliant idea that you will monitor the temperature of your mixture every minute for the entire lab. You will then plot the rate of change for the entire duration of the lab.nBeing a promising computer scientist, you know you can automate part of this procedure, so you are writing a program you can run on your laptop during chemistry labs. (Laptops are only occasionally dissolved by the chemicals used in such labs.) You will write a program that will let you enter in each temperature as you observe it. The program will then calculate the difference between this temperature and the previous one, and print out the difference. Then you can feed this input into a simple graphing program and finish your plot before you leave the chemistry lab.nnnInputnnThe input is a series of temperatures, one per line, ranging from -10 to 200. The temperatures may be specified up to two decimal places. After the final observation, the number 999 will indicate the end of the input data stream. All data sets will have at least two temperature observations.nnnOutputnnYour program should output a series of differences between each temperature and the previous temperature. There is one fewer difference observed than the number of temperature observations (output nothing for the first temperature). Differences are always output to two decimal points, with no leading zeroes (except for the ones place for a number less than 1, such as 0.01) or spaces.nnAfter the final output, print a line with "End of Output"nnnSample Inputnn10.0n12.05n30.25n20n999nnnSample Outputnn2.05n18.20n-10.25nEnd of Output 问答

a simple question about deploying a simple bean in deploytool of j2eesdk

04-19

distribute: D:\examples\MyFirstExample.earrn*** Operation failed:rnjava.lang.IllegalStateException: Premature end of file.rnrnat com.sun.enterprise.deployapi.SunDeploymentManager.distribute(SunDeploymentManager.java:728)rnrnat com.sun.enterprise.deployapi.SunDeploymentManager.distribute(SunDeploymentManager.java:249)rnrnat com.sun.enterprise.tools.deployment.ui.deploy.DeploymentPlatform._distribute(DeploymentPlatform.java:955)rnrnat com.sun.enterprise.tools.deployment.ui.deploy.DeploymentPlatform._deploy(DeploymentPlatform.java:1051)rnrnat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rnrnat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rnrnat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rnrnat java.lang.reflect.Method.invoke(Method.java:324)rnrnat com.sun.enterprise.tools.deployment.ui.utils.UIActionDispatcher.invoke(UIActionDispatcher.java:365)rnrnat com.sun.enterprise.tools.deployment.ui.utils.UIActionDispatcher.invoke(UIActionDispatcher.java:387)rnrnat com.sun.enterprise.tools.deployment.ui.deploy.DeploymentPlatform$DeploymentProcess.run(DeploymentPlatform.java:1492)rnrnat com.sun.enterprise.tools.deployment.ui.utils.ExecProcess$ThreadProcess.run(ExecProcess.java:570)rnrnat java.lang.Thread.run(Thread.java:536)rnrnrn**********************************************************************rn[Completed (time=0.4sec, status=20)]rn**********************************************************************rnrnrnthe source code has compiled successfully,so there should be no problem in the files itseldrnrnand the deployment descriptor is as follows:rnrnrnrn Your first EJB application rnrn JUST A TESTrnrn rnrn rnrn Examplernrn examples.ExampleHomernrn examples.Examplernrn examples.ExampleBeanrnrn Statelessrnrn Containerrnrn rnrn rnrnrnrnthe sun-j2ee-ri.xml is as follows:rnrnrnrnrn rn rn Examplern Examplern rn rn rnrnrnrnand I am sure the directory structures is all rightrn.The problem may result from deploying,but I just do not know why?rni am using standard deploytool in j2eesdkrnrnthank you very much!!!!!!!rnrn 论坛

没有更多推荐了,返回首页