473,413 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

IP and hostname comparing

Anyone who can help me with a IP thingie? I want to compare a IP adress
with a IP "String" with wildcards (*)

like 127.0.0.1 equals to 127.*.*.*
and 255.255.255.0 equals *.255.255.0
I want the wildcards to work in all the places eg. *.*.*.* will equal all Ip
adresses
And it would also be great if someone could help me with a regex or
something that can help me to compare hostnames

like *.no equals every hostname that ends with .no
and some*.no wil equal every hostname that begins with some and ends with
..no

Jul 17 '05 #1
3 2830
"Bjerkås" <bj******@sensewave.com> wrote in message
news:<Tn********************@news2.e.nsc.no>...

I want to compare a IP adress with a IP "String" with wildcards (*)

like 127.0.0.1 equals to 127.*.*.*
and 255.255.255.0 equals *.255.255.0


$ip1 = '127.0.0.1';
$ip2 = '127.*.*.*';
$numbers1 = explode ('.', $ip1);
$numbers2 = explode ('.', $ip2);
for ($i = 0; $i < 4; $i++) {
if (($numbers1[$i] == $numbers2[$i]) or
($numbers1[$i] == '*') or
($numbers1[$i] == '*')) {
$match = true;
} else {
$match = false;
break;
}
}
if ($match) {
echo $ip1, ' matches ', $ip2;
} else {
echo $ip1, ' does not match ', $ip2;
}

Cheers,
NC
Jul 17 '05 #2
What does the explode function do anyways

"Nikolai Chuvakhin" <nc@iname.com> wrote in message
news:32**************************@posting.google.c om...
"Bjerkås" <bj******@sensewave.com> wrote in message
news:<Tn********************@news2.e.nsc.no>...

I want to compare a IP adress with a IP "String" with wildcards (*)

like 127.0.0.1 equals to 127.*.*.*
and 255.255.255.0 equals *.255.255.0


$ip1 = '127.0.0.1';
$ip2 = '127.*.*.*';
$numbers1 = explode ('.', $ip1);
$numbers2 = explode ('.', $ip2);
for ($i = 0; $i < 4; $i++) {
if (($numbers1[$i] == $numbers2[$i]) or
($numbers1[$i] == '*') or
($numbers1[$i] == '*')) {
$match = true;
} else {
$match = false;
break;
}
}
if ($match) {
echo $ip1, ' matches ', $ip2;
} else {
echo $ip1, ' does not match ', $ip2;
}

Cheers,
NC

Jul 17 '05 #3
I noticed that Message-ID: <0f******************@twister.austin.rr.com>
from Tesla contained the following:
What does the explode function do anyways


Turns a string into an array.

RTFM

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Claus van de Vlierd | last post by:
Hello , a) in the following script (under RedHat AS3 with PHP 4.3.2 ) I make a "DB::connect" to an existing "mysql" database named "docu_files_of_cvdv" . The strange thing is : it works --...
2
by: Lukas Schnieper | last post by:
Hi How can i get the hostname of my Linux PC? I tried os.system('hostname') but i cant save the hostname in a variable like hostname = os.system('hostname') thanks Lukas Schnieper
2
by: Tim Veldhuizen | last post by:
Hi all! I'm attempting at writing a networked program. It is going to be a threaded irc server in c++ using almost nothing but oop code. And it needs to know the full hostname of the users that...
2
by: James M. | last post by:
I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup with NLB (single Affinity, also using SQLServer session state) that are hosting a few .NET ASP web applications under the Default Website...
3
by: HiChetu | last post by:
I have a host which has two NIC cards; one configured for LAN connections, and another for external connections. Say the ip address are 1) x.x.x.x - for LAN 2) y.y.y.y - for external ...
0
by: James M via .NET 247 | last post by:
(I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup withNLB (single Affinity, also using SQLServer session state) thatare hosting a few .NET ASP web applications under the DefaultWebsite in...
6
by: Eric Rechter | last post by:
Hi, I only want to display the provider name from a hostname, so I need to divide the string to take only de characters from after the before last dot. For example: ...
2
by: slinkp | last post by:
Can anybody explain this one? pw@kermit ~ $ python Python 2.4.3 (#1, Jul 27 2006, 13:07:44) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most...
3
by: Mark Delaney | last post by:
When using the MS SQL 2005 JDBC driver, I now need to have the DNS name resolution to the client correctly set up. If not I get the following error: SQLState: 08S01 SQLError: 0 Message:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.