database - SQL Script - Check if a IP has been black listed -


I am studying SQL, and I would like your advice, to see if this code is written correctly or The better way is to do this.

  • To allow spitting in an IP address 4 octet
  • An SPROC which allows to check whether the IP Black is listed or Please do not tell me! ! Thanks

      - Create Black Listed Table Tables UtlBlacklistedIPs (TINYINT octet1, TINYINT octet2, TINYINT octet3, TINYINT octet4); 1 SPRC  
      - Convert an IP Address in 4 octets for DB storage. Process DB.StoreIPOctatsAvoice as an APIP CHAR (15) Start NOCOUNT set on UtlBlacklistedIPs (octet1, octet2 (Octet3, octet4 (@ AP, 1)) END  

    2 SPROC

      - SPROC check if an IP address has been blacklisted Create the process dbo.sproc SetIp @ip CHAR (15) as set on NOCOUNT declared @ octet1 tinyint, @ octet2 tinyint, @ octet3 tinyint, @ octet4 tinyint; SET @ octet1 = CONVERT (Tinton, PARSENAME (@ AP, 4)); SET @ octet2 = CONVERT (Tinent, PARSENAME (@ AP, 3)); SET @ octet3 = CONVERT (TININT, PARSENAME (@, 2)); SET @ octet4 = CONVERT (TININT, PARSENAME (@, 1)); If present (select octet1, octet2, octet3, octet4 from utlBlacklistedIPs octet1 = octet1 and octet2 = octet2 and octet3 = octet3 and octet4 = @ octet4) start print 'ip:' + @ ip + end all other 'Blacklist is' BEGIN PRINT 'IP:' + @ IP + 'Black is not listed' end and end  

    some values ​​

      - Dummy values Insert @ INT SET @i = 0 WHILE @i & lt; 2000 launched EXEC dbo.storeIPoctetsv1 @ip = '204.71.34.21' EXEC dbo.storeIPoctetsv1 @ip = '12 .38.145.32 'EXEC dbo.storeIPoctetsv1 @ip =' 127.0.0.1 '@i set = @i +1 end < / Code> 

    sproc

      - Use sproc EXEC dbo.sprocCheckIp '125.254.125.111' - No, Blacklist IP EXEC dbo.sprocCheckIp '204.71.34.21 I think that you can use it outside the database. I do not want to use it in the black list. Are, probably in .net? In that case, I structure again like this:  
    • With four octets as SPC input to store black-listed IP
    • Someone Also to check the IP, use four octets as SPRC input and using 0 or 1 output (using return , do not use PRINT ). >
    • SQL Server has very bad string handling, so you have a class ip on a static method int [] ToOctets (ST) Ring IP) are much better than writing which handles it for you. You will use it like this: var octs = Ip.ToOctets ("213.82.158.93")
    • When you check whether an IP is blacklisted or not, you Calling
  • ExecuteScalar (or whatever method to obtain a scalar value from a stored procedure can be called with the connector from you).

    Comments

    Popular posts from this blog

    c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

    Calling GetGUIThreadInfo from Outlook VBA -

    Obfuscating Python code? -