当前位置: 首页>>代码示例>>PHP>>正文


PHP IPAddress::setArrayFromAddress方法代码示例

本文整理汇总了PHP中IPAddress::setArrayFromAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP IPAddress::setArrayFromAddress方法的具体用法?PHP IPAddress::setArrayFromAddress怎么用?PHP IPAddress::setArrayFromAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPAddress的用法示例。


在下文中一共展示了IPAddress::setArrayFromAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createNetworkNameFromItem

/**
 * @param $itemtype
 * @param $items_id
 * @param $main_items_id
 * @param $main_itemtype
 * @param $entities_id
 * @param $IP
**/
function createNetworkNameFromItem($itemtype, $items_id, $main_items_id, $main_itemtype, $entities_id, $IP)
{
    global $migration;
    // Using gethostbyaddr() allows us to define its reald internet name according to its IP.
    //   But each gethostbyaddr() may reach several milliseconds. With very large number of
    //   Networkports or NetworkeEquipment, the migration may take several minutes or hours ...
    //$computerName = gethostbyaddr($IP);
    $computerName = $IP;
    if ($computerName != $IP) {
        $position = strpos($computerName, ".");
        $name = substr($computerName, 0, $position);
        $domain = substr($computerName, $position + 1);
        $query = "SELECT `id`\n                   FROM `glpi_fqdns`\n                   WHERE `fqdn` = '{$domain}'";
        $result = $DB->query($query);
        if ($DB->numrows($result) == 1) {
            $data = $DB->fetch_assoc($result);
            $domainID = $data['id'];
        }
    } else {
        $name = "migration-" . str_replace('.', '-', $computerName);
        $domainID = 0;
    }
    $IPaddress = new IPAddress();
    if ($IPaddress->setAddressFromString($IP)) {
        $input = array('name' => $name, 'fqdns_id' => $domainID, 'entities_id' => $entities_id, 'items_id' => $items_id, 'itemtype' => $itemtype);
        $networknames_id = $migration->insertInTable('glpi_networknames', $input);
        $input = $IPaddress->setArrayFromAddress(array('entities_id' => $entities_id, 'itemtype' => 'NetworkName', 'items_id' => $networknames_id), "version", "name", "binary");
        $migration->insertInTable($IPaddress->getTable(), $input);
    } else {
        // Don't add the NetworkName if the address is not valid
        addNetworkPortMigrationError($items_id, 'invalid_address');
        logNetworkPortError('invalid IP address', $items_id, $main_itemtype, $main_items_id, "{$IP}");
    }
    unset($IPaddress);
}
开发者ID:jose-martins,项目名称:glpi,代码行数:43,代码来源:update_0831_084.php


注:本文中的IPAddress::setArrayFromAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。