I want to use
execute xp_cmdshell 'ping @ip'
You cannot reference parameters directly within xp_cmdshell, so you have to concatenate the value when creating the command. I recommend reading: https://msdn.microsoft.com/en-us/library/ms175046.aspx
In your example, you would do something like:
DECLARE @cmd nvarchar(4000); SET @cmd = 'ping ' + @ip; EXEC xp_cmdshell @cmd;