The two statements we see in the voting filter: String ip = request. getRemoteAddr (); and long ipnum = StringHandler. getIpNum (ip); the first one is to obtain the ip address of the client, and the second statement is to convert the obtained ip address into a growth integer. Here, the static method getIpNum (String ip) in the StringHandler class is called. Let's take a look at how this is implemented:
[Java]
Public class StringHandler {
Public static long getIpNum (String ip ){
Long ipNum = 0;
If (ip! = Null &&! Ip. equals ("")){
String [] subips = ip. split ("\\.");
For (int I = 0; I <subips. length; I ++ ){
IpNum + = Integer. parseInt (subips [I]);
If (I <subips. length-1)
IpNum = ipNum <8;
}
}
Return ipNum;
}
}
Public class StringHandler {
Public static long getIpNum (String ip ){
Long ipNum = 0;
If (ip! = Null &&! Ip. equals ("")){
String [] subips = ip. split ("\\.");
For (int I = 0; I <subips. length; I ++ ){
IpNum + = Integer. parseInt (subips [I]);
If (I <subips. length-1)
IpNum = ipNum <8;
}
}
Return ipNum;
}
} Note: ipNum = ipNum <8; shifts the binary number of ipNum eight places to the left.