http://php.net/manual/en/function.long2ip.php
PHP: ip2long - Manual http://php.net/manual/en/function.ip2long.php Technical Reference: Communications, Volume 2 - inet_addr Subroutine http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/libs/commtrf2/inet_addr.htm
import socket, struct

def ip2long(ip):
packedIP = socket.inet_aton(ip)
return struct.unpack("!L", packedIP)[0] def log2ip(long):
return socket.inet_ntoa(struct.pack('!L', long))

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2


inet_addr Subroutine

Purpose

Converts Internet addresses to Internet numbers.

Library

Standard C Library (libc.a)

Syntax

#include <sys/socket.h>
#include <sys/socketvar.h>
#include <netinet/in.h>
#include <arpa/inet.h>


unsigned long inet_addr ( CharString)
char *CharString;

Description

The inet_addr subroutine converts an ASCII string containing a valid Internet address using dot notation into an Internet address number typed as an unsigned long value. An example of dot notation is 120.121.5.123. The inet_addr subroutine returns an error value if the Internet address notation in the ASCII string supplied by the application is not valid.

Note: Although they both convert Internet addresses in dot notation to Internet numbers, the inet_addr subroutine and inet_network process ASCII strings differently. When an application gives the inet_addr subroutine a string containing an Internet address value without a delimiter, the subroutine returns the logical product of the value represented by the string and 0xFFFFFFFF. For any other Internet address, if the value of the fields exceeds the previously defined limits, the inet_addr subroutine returns an error value of -1.

When an application gives the inet_network subroutine a string containing an Internet address value without a delimiter, the inet_network subroutine returns the logical product of the value represented by the string and 0xFF. For any other Internet address, the subroutine returns an error value of -1 if the value of the fields exceeds the previously defined limits.

Sample return values for each subroutine are as follows:


Application string inet_addr returns inet_netowork returns
0x1234567890abcdef 0x1234567890abcdef. 256.257.258.259 0x090abcdef 0xFFFFFFFF (= -1) 0xFFFFFFFF (= -1) 0x000000ef 0x0000ef00 0x00010203

The ASCII string for the inet_addr subroutine must conform to the following format:

string::= field | field delimited_field^1-3 | delimited_field^1-3
delimited_field::= delimiter field | delimiter
delimiter::= .
field::= 0X | 0x | 0Xhexadecimal* | 0x hexadecimal* | decimal* | 0 octal
hexadecimal::= decimal |a|b|c|d|e|f|A|B|C|D|E|F
decimal::= octal |8|9
octal::= 0|1|2|3|4|5|6|7

Notes:

  1. ^n indicates n repetitions of a pattern.
  2. ^n-m indicates n to m repetitions of a pattern.
  3. * indicates 0 or more repetitions of a pattern, up to environmental limits.
  4. The Backus Naur form (BNF) description states the space character, if one is used. Text indicates text, not a BNF symbol.

The inet_addr subroutine requires an application to terminate the string with a null terminator (0x00) or a space (0x30). The string is considered invalid if the application does not end it with a null terminator or a space. The subroutine ignores characters trailing a space.

The following describes the restrictions on the field values for the inet_addr subroutine:

Format Field Restrictions (in decimal)
a Value_a < 4,294,967,296
a.b Value_a < 256; Value_b < 16,777,216
a.b.c Value_a < 256; Value_b < 256; Value_c < 65536
a.b.c.d Value_a < 256; Value_b < 256; Value_c < 256; Value_d < 256

Applications that use the inet_addr subroutine can enter field values exceeding these restrictions. The subroutine accepts the least significant bits up to an integer in length, then checks whether the truncated value exceeds the maximum field value. For example, if an application enters a field value of 0x1234567890 and the system uses 16 bits per integer, then the inet_addr subroutine uses bits 0 -15. The subroutine returns 0x34567890.

Applications can omit field values between delimiters. The inet_addr subroutine interprets empty fields as 0.

Notes:

  1. The inet_addr subroutine does not check the pointer to the ASCII string. The user must ensure the validity of the address in the ASCII string.
  2. The application must verify that the network and host IDs for the Internet address conform to either a Class A, B, or C Internet address. The inet_attr subroutine processes any other number as a Class C address.

Parameters

CharString Represents a string of characters in the Internet address form.

Return Values

For valid input strings, the inet_addr subroutine returns an unsigned long value comprised of the bit patterns of the input fields concatenated together. The subroutine places the first pattern in the most significant position and appends any subsequent patterns to the next most significant positions.

The inet_addr subroutine returns an error value of -1 for invalid strings.

Note: An Internet address with a dot notation value of 255.255.255.255 or its equivalent in a different base format causes the inet_addr subroutine to return an unsigned long value of 4294967295. This value is identical to the unsigned representation of the error value. Otherwise, the inet_addr subroutine considers 255.255.255.255 a valid Internet address.

Implementation Specifics

The inet_addr subroutine is part of Base Operating System (BOS) Runtime.

All applications containing the inet_addr subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.

Files

/etc/hosts
                          Contains host names.
/etc/networks
                          Contains network names.

Related Information

The endhostent subroutine, endnetent subroutine, gethostbyaddr subroutine, gethostbyname subroutine, getnetbyaddr subroutine, getnetbyname subroutine, getnetent subroutine, inet_Inaof subroutine, inet_makeaddr subroutine, inet_netof subroutine, inet_network subroutine, inet_ntoa subroutine, sethostent subroutine, setnetent subroutine.

Sockets Overview and Understanding Network Address Translation in AIX 5L Version 5.1 Communications Programming Concepts.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Converts Internet addresses to Internet numbers. ip2long long2ip的更多相关文章

  1. [区分] 1.计算机网络/internet(互联网) 2.Internet(因特网) 3.www/web(万维网)

    internet(互联网或互连网)是一个通用名词,泛指由多个计算机网络互联而成的虚拟网络.Inernet(因特网)是一个专用名词,指当前全球最大的.开放的.由众多网络相互连接而成的特定的计算机网络,它 ...

  2. 读书笔记二 How Does the Internet work?

    原文链接:  https://web.stanford.edu/class/msande91si/www-spr04/readings/week1/InternetWhitepaper.htm 先写写 ...

  3. 企业IT管理员IE11升级指南【6】—— Internet Explorer 11面向IT专业人员的常见问题

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  4. TWebBrowser 调用最新版的Ie Internet Feature Controls (B..C)

    Internet Feature Controls (B..C)   Updated: July 2012 This article describes feature controls with n ...

  5. Internet Explorer 无法启用 JavaScript 怎么办?

    在 Internet Expllorer 8/9 中,有些同学在浏览网页时,收到提示:“需要启用 JavaScript …”,并且会发现网页上某些功能不能用了,比如点击网页里的按钮没反应等等. 怎么启 ...

  6. 解决安装失败的 Internet Explorer 11

    注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成.微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章.然而由机器翻译的文章并不总是完美的.它 ...

  7. AWS中的Internet 网关

    nternet 网关是一种横向扩展.支持冗余且高度可用的 VPC 组件,可实现 VPC 中的实例与 Internet 之间的通信.因此它不会对网络流量造成可用性风险或带宽限制. Internet 网关 ...

  8. 登陆Oracle EBS的Form遇到问题Internet Explorer has modified this page to help prevent cross-site scripting

    登陆Oracle EBS的Form遇到问题Internet Explorer has modified this page to help prevent cross-site scripting 今 ...

  9. internet与Internet的区别

    internet是用一个共同的协议族把多个网络连接在一起.而Internet指的是世界范围内通过TCP/IP互相通信的所有主机集合(超过1 0 0万台).Internet是一个internet,但in ...

随机推荐

  1. “互联网+”取代O2O将成为2016最大风口

    2016年的最大风口是“互联网+”,经历了O2O的洗礼,B2C服务的全线崛起.跨界与场景打造的极致体验,从0到1的产业开放,都将在这一年集体爆发,“互联网+”比O2O更加接地气,更具有完整的商业模式和 ...

  2. 使用Nginx Lua实现redis高性能http接口

    使用Nginx Lua实现redis高性能http接口 时间 -- :: 峰云就她了 原文 http://xiaorui.cc/2015/01/27/使用nginx-lua实现redis高性能http ...

  3. JQuery EasyUI 请求/加载 两次

    解决方案如下: Html页面中的Table标签中包含class属性(class="easyui-datagrid"),删除即可.

  4. java性能监控工具:jmap命令详解

    .命令基本概述 Jmap是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本.打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数 ...

  5. Jquery学习笔记(11)--jquery的ajax删除用户,非常简单!

    jquery的ajax,简直简单!!只要一个$.get(url,map,function)就搞定了! index.php: <!DOCTYPE html> <html lang=&q ...

  6. [转]wordpress安装插件的3种方式

    WordPress插件安装方法有几种?WordPress是一种使用PHP语言开发的博客平台,有些用户不知道怎么安装WordPress插件和主题的,所以今天小编就为大家介绍几种WordPress插件安装 ...

  7. 网络协议之p2p---一个简单的nat 穿透demo

    http://www.pudn.com/downloads64/sourcecode/p2p/detail228131.html http://www.pudn.com/downloads15/sou ...

  8. 邮件正文及其附件的发送的C++实现

     这段代码我花了整整一天来编写,假设转载,请注明出处,谢谢!    前面的一篇文章已经讲了怎样发送邮件正文,原理我就不再叙述了.要了解的同学请到这里查看!    http://blog.csdn.ne ...

  9. 将Centos的yum源更换为国内的阿里云(163)源

    阿里云是最近新出的一个镜像源.得益于阿里云的高速发展,这么大的需求,肯定会推出自己的镜像源.阿里云Linux安装镜像源地址:http://mirrors.aliyun.com/ CentOS系统更换软 ...

  10. jvm之 国际酒店 一次报表 load数据死循环导致的FULLGC

    从目前这几天的运行情况看,每天晚上0点到3点,应该是你们那边有大数据任务处理,在这个时间段,SOA会频繁报ZK断开重联的告警,见下图.   类似的问题,在CRM系统上也有出现过,我们dump内存,分析 ...