|
| |||||||||
| Tags: address, ado net, convert, ip address |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| How to Convert IP Address to Long in ADO?
Hello, I want to know the code from which I can able to convert the IP address to the long with the help of Ado.net. I have tried it, but it is not possible for me to get the solution to achieve it. So, if you are having any solution to solve this problem then please help me to solve my problem. Thank you in advance. |
|
#2
| |||
| |||
| Re: How to Convert IP Address to Long in ADO?
Hey, if you make use of the code below then you will able to get the solution for your problem: Code: public static long IPToLONG(string ipaddressAddress)
{
System.Net.IPAddress ipaddress;
if (System.Net.IPAddress.TryParse(ipaddressAddress, out ipaddress))
{
byte[] bt = ipaddress.GetAddressBytes();
return (long)((bt[0] << 24) | (bt[1] << 16) |
(bt[2] << 8) | bt[3]);
}
else
return 0;
} |
|
#3
| ||||
| ||||
| Re: How to Convert IP Address to Long in ADO?
Hello, I am not having idea to convert the IP address to Long in ADO, but I can help you to convert the Long value to the IP address. Just make use of the code below: Code: public static string ConvertLongToIP(long ipLong)
{
StringBuilder strBuild = new StringBuilder();
long Two, One;
Two = ipLong;
One = Two / (256 * 256 * 256);
Two = Two - (One * 256 * 256 * 256);
strBuild.Append(Convert.ToString(One)).Append(".");
One = Two / (256 * 256);
Two = Two - (One * 256 * 256);
strBuild.Append(Convert.ToString(One)).Append(".");
One = Two / 256;
Two = Two - (One * 256);
strBuild.Append(Convert.ToString(One)).Append(".");
One = Two;
Two = Two - One;
strBuild.Append(Convert.ToString(One));
return strBuild.ToString().ToLower();
} |
|
#4
| ||||
| ||||
| Re: How to Convert IP Address to Long in ADO?
Hello, I don't know how to convert the IP address to long in ADO.net, But while searching on internet I have got the solution below for achieving it: Code: function iptolong(ipadr) result=0 str=split(ipadr,".") for ix=0 to 3 expn=3-ix result=result + str(ix) * 256 ^ expn next iptolong=result end function |
|
#5
| ||||
| ||||
| Re: How to Convert IP Address to Long in ADO?
Hey, I am having knowledge of C. And that is why I have tried it using c language. I think it will help you to get your logic for your solution: Code: #include <stdio.h>
#include <string.h>
#include<stdlib.h>
main()
{
int num = 1,z;
long Lnum,longnum2;
char ch[]=" 168.1.2.3";
char *string;
char str2[16];
printf("String: %s\n", str);
string = strtok(str, ".");
strcpy(str2,string);
while (1)
{
string = strtok(NULL, ".");
if (string == NULL)
{
exit(0);
}
strcat(str2,string);
Lnum=atol(str2);
printf("long integer is %ld \n",Lnum);
} |
|
#6
| ||||
| ||||
| Re: How to Convert IP Address to Long in ADO?
Hey, hope the solution below will help you and you will get your problem solved. You just need to make use of the code below in your program: Code: string[] str = Request.UserHostAddress.Split('.');
long ipadd = 19812151 * Convert.ToInt32(str[0]) + 65536 * Convert.ToInt32(str[1]) + 256 * Convert.ToInt32(str[2]) + Convert.ToInt32(str[3]); |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to Convert IP Address to Long in ADO?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Vista takes a long time from start to long in on SBS2003 network...... | mlai | Windows Vista Network | 10 | 06-11-2010 04:40 AM |
| How to convert email address from window mail to outlook express | Leg | Windows Vista Mail | 4 | 31-05-2010 10:16 AM |
| Convert your Dynamic IP to Static IP address | Larry ward | Tips & Tweaks | 2 | 23-04-2010 04:01 AM |
| Convert IP address to array of bytes | Gunner 1 | Software Development | 5 | 03-03-2010 11:54 AM |
| How to convert an RGB value to a long or a long to RGB? | Sanket07 | Software Development | 2 | 26-02-2009 08:42 PM |