Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> jak to przerobić na normalny IP - `ipaddr` int(16)
Elber
post
Post #1





Grupa: Zarejestrowani
Postów: 381
Pomógł: 12
Dołączył: 9.07.2007

Ostrzeżenie: (0%)
-----


Witam, mam taki problem, postawiłem sobie LMS, i wszystko dobrze działa (IMG:http://forum.php.pl/style_emoticons/default/haha.gif) Ale w bazie zamiast IP, które dodaje czyli 192.168.0.1 jest coś takiego 3232237834 i chciałem sie zapytać jak to działa (IMG:http://forum.php.pl/style_emoticons/default/haha.gif) Jak to sie potem zamienia spowrotem w normalne IP (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Tak wygląda struktura tabeli:
Kod
CREATE TABLE `nodes` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(16) NOT NULL default '',
  `mac` varchar(20) NOT NULL default '',
  `ipaddr` int(16) unsigned NOT NULL default '0',
  `ipaddr_pub` int(16) unsigned NOT NULL default '0',
  `passwd` varchar(32) NOT NULL default '',
  `ownerid` int(11) NOT NULL default '0',
  `creationdate` int(11) NOT NULL default '0',
  `moddate` int(11) NOT NULL default '0',
  `creatorid` int(11) NOT NULL default '0',
  `modid` int(11) NOT NULL default '0',
  `netdev` int(11) NOT NULL default '0',
  `linktype` tinyint(1) NOT NULL default '0',
  `access` tinyint(1) NOT NULL default '1',
  `warning` tinyint(1) NOT NULL default '0',
  `lastonline` int(11) NOT NULL default '0',
  `info` text NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`),
  UNIQUE KEY `ipaddr` (`ipaddr`),
  KEY `netdev` (`netdev`)
) TYPE=MyISAM  AUTO_INCREMENT=1855;

A tak kawałek zrzutu:
Kod
INSERT INTO `nodes` (`id`, `name`, `mac`, `ipaddr`, `ipaddr_pub`, `passwd`, `ownerid`, `creationdate`, `moddate`, `creatorid`, `modid`, `netdev`, `linktype`, `access`, `warning`, `lastonline`, `info`) VALUES
(3, 'Test', '00:09:92:01:85:B2', 3232237834, 0, '', 0, 1161669555, 1161669577, 3, 3, 1, 0, 1, 0, 0, ''),


Ten post edytował Elber 1.02.2008, 09:45:21
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 5)
heaven
post
Post #2





Grupa: Nieautoryzowani
Postów: 92
Pomógł: 15
Dołączył: 21.10.2006

Ostrzeżenie: (0%)
-----


Możesz pobrać juz z bazy Twoja oczekiwana wartosc w ten sposob
  1. SELECT
  2. CONCAT_WS('.',ipaddr >> 24,(ipaddr & (255 << 16)) >> 16,(ipaddr & (255 << 8)) >> 8,(ipaddr & 255)) AS adres_ip
  3. FROM nodes WHERE ......

Teraz mozesz to wstawic to w kazde miejsce i zastapic ipaddr inna kolumna z adresem ip.

Ip przechowwane tu jest za pomoca int a nie jako text. adres sklada sie z 4 pol ktore maja wartosc od 0 do 255
czyli pojedyncze pole potrzebuje 8 bitow czyli jeden bajt a wiec do zapisu ip jako int potrzeba 4 bajtow i teraz tylko trzeba wyciagac paczki 8 bitow zaczynajac od lewej

Ten post edytował heaven 1.02.2008, 10:02:26
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #3





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


http://dev.mysql.com/doc/refman/5.0/en/mis...-functions.html

INET_*()
Go to the top of the page
+Quote Post
Elber
post
Post #4





Grupa: Zarejestrowani
Postów: 381
Pomógł: 12
Dołączył: 9.07.2007

Ostrzeżenie: (0%)
-----


Jak by wyglądał skrypt php, który zamienił by wszystkie adresy na 192.168.... i wypisał je (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) Bo sie męczę i nie moge wymyślić ;(
Go to the top of the page
+Quote Post
SirZooro
post
Post #5





Grupa: Zarejestrowani
Postów: 243
Pomógł: 32
Dołączył: 14.06.2007

Ostrzeżenie: (0%)
-----


Oj przecież poprzednicy wszystko napisali co trzeba (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
  1. SELECT inet_ntoa(ipaddr) ...

albo
  1. <?php
  2. $addr_txt = long2ip($ip);
  3. ?>

Dalej pomęcz się już sam (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
grzywka18
post
Post #6





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 22.07.2008

Ostrzeżenie: (0%)
-----


A ja zapytam tylko ze o zamiane wartosci z tabeli "lastonline" ?
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.12.2025 - 22:06